当前位置:网站首页>C # connect to the database to complete the operation of adding, deleting, modifying and querying
C # connect to the database to complete the operation of adding, deleting, modifying and querying
2022-06-28 20:03:00 【Game programming】
Preface
Introduce C# Connect to the database to complete the operations of adding, deleting, modifying and querying
One 、 download
1、 Download package
Select menu bar tool ->NuGet Package manager -> Manage solutions NuGet Package , Select browse , Input MySql.Data, Search and download .

Two 、 Use steps
using System;using MySql.Data.MySqlClient;namespace Demo{ class Program { private static MySqlConnectionStringBuilder mysqlbuilder = new MySqlConnectionStringBuilder(); private static MySqlConnection mysqlconnection; static void Main(String[] args) { mysqlbuilder.UserID = "root"; mysqlbuilder.Password = "123456"; mysqlbuilder.Server = "localhost"; mysqlbuilder.Database = "springboot"; mysqlconnection = new MySqlConnection(mysqlbuilder.ConnectionString); mysqlconnection.Open(); // increase /*Console.WriteLine(" Please enter a user name :"); string name = Console.ReadLine(); Console.WriteLine(" Please enter age :"); string age = Console.ReadLine(); string sql = "insert into users(name,age) values(@name,@age)"; MySqlCommand cmd = new MySqlCommand(sql, mysqlconnection); cmd.Parameters.Add(new MySqlParameter("@name", name)); cmd.Parameters.Add(new MySqlParameter("@age", age)); int rows=cmd.ExecuteNonQuery(); if (rows == 1) { Console.WriteLine(" Registered successfully !"); } else { Console.WriteLine(" Registration failed !"); }*/ // Delete /* Console.WriteLine(" Please enter id:"); string id = Console.ReadLine(); string sql = "delete from users where [email protected]"; MySqlCommand cmd = new MySqlCommand(sql, mysqlconnection); cmd.Parameters.Add(new MySqlParameter("@id", id)); int rows = cmd.ExecuteNonQuery(); if (rows < 0) { Console.WriteLine(" Delete failed !"); } else { Console.WriteLine(" Delete successful !"); } mysqlconnection.Close();*/ // modify Console.WriteLine(" Please enter ID:"); string id = Console.ReadLine(); Console.WriteLine(" Please enter age :"); string age = Console.ReadLine(); string sql = "update users set [email protected] where [email protected]"; MySqlCommand cmd = new MySqlCommand(sql, mysqlconnection); cmd.Parameters.Add(new MySqlParameter("@age", age)); cmd.Parameters.Add(new MySqlParameter("@id", id)); int rows = cmd.ExecuteNonQuery(); if (rows < 0) { Console.WriteLine(" Modification failed !"); } else { Console.WriteLine(" Modification successful !"); } mysqlconnection.Close(); // Inquire about /* string sql = "select * from users"; MySqlCommand cmd = new MySqlCommand(sql, mysqlconnection); MySqlDataReader reader = cmd.ExecuteReader(); Console.WriteLine("id\tname\tage"); while(reader.Read()) { Console.Write(reader.GetInt32(0) + "\t"); if(reader.IsDBNull(1)) { Console.Write("\t"); } else { Console.Write(reader.GetString("name") + "\t"); } if (reader.IsDBNull(2)) { Console.Write(" "); } else { Console.WriteLine(reader.GetString(2) + "\t"); } } mysqlconnection.Close();*/ } }}author : the greatest hero in the world tr
Game programming , A game development favorite ~
If the picture is not displayed for a long time , Please use Chrome Kernel browser .
边栏推荐
- kettle(六):基于Kettle的数据库全量备份
- JVM memory structure
- 【算法篇】刷了两道大厂面试题,含泪 ”重学数组“
- Configuration du mode tcwind
- Quaternion quaternion and Euler angle Transformation in Ros
- Severity code description project file line suppress status error lnk2038 detected a mismatch of "runtimelibrary": the value "md\u dynamicrelease" does not match the value "mdd\u dynamicde"
- How does redis implement inventory deduction? How to prevent oversold?
- csdn涨薪技术-Selenium自动化测试全栈总结
- R语言GLM广义线性模型:逻辑回归、泊松回归拟合小鼠临床试验数据(剂量和反应)示例和自测题
- Rsync remote synchronization
猜你喜欢

Markdown mermaid种草(1)_ mermaid简介

Tencent tangdaosheng: facing the new world of digital and real integration, developers are the most important "architects"

Paper notes: universal value function approvers

Ali open source (easyexcel)

From design delivery to development, it is easy and efficient!

5G NR MBS架构介绍

图神经网络入门 (GNN, GCN)

CSDN salary increase technology selenium automated test stack summary

Analysys analytics' 2022 China Banking privacy computing platform supplier strength matrix analysis' research activity was officially launched

Markdown drawing Mermaid practical tutorial
随机推荐
Risc-v instruction set
电子科大(申恒涛团队)&京东AI(梅涛团队)提出用于视频问答的结构化双流注意网络,性能SOTA!优于基于双视频表示的方法!...
Redis 如何实现库存扣减操作?如何防止商品被超卖?
SQL server2019 create a new SQL server authentication user name and log in
Ali open source (easyexcel)
C # application interface development foundation - form control
Demo of integrated development of intelligent computing system 3 plugin
bluecmsv1.6代码审计
Day88.七牛云: 房源图片、用户头像上传
5g NR MBS architecture introduction
From design delivery to development, it is easy and efficient!
F (x) construct the equation, calculate the partial derivative by gradient descent, determine the partial derivative adjustment by loss function, and deal with nonlinear problems by activation functio
MDM data analysis function description
Figure introduction to neural networks (GNN, GCN)
Demo of intelligent computing system 2 bangc operator development (heterogeneous programming flow of CPU and mlu270)
2788.Cifera
[algorithm] I brushed two big factory interview questions and learned array again with tears in my eyes“
阿里开源(EasyExcel)
C语言局部变量与全局变量重名时的优先级问题(当局部变量和全局变量同时存在的时候,优先引用局部变量,而不去引用全局变量)
April 10, 2022 -- take the first step with C -- use C from Net class library call method (not understood)