当前位置:网站首页>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 .
边栏推荐
- Demo of intelligent computing system 2 bangc operator development (heterogeneous programming flow of CPU and mlu270)
- Demo of integrated development of intelligent computing system 3 plugin
- How does win11 slim down the system disk? Slimming method of win11 system disk
- rsync远程同步
- 30讲 线性代数 第四讲 线性方程组
- easypoi
- Priority problem when local variables and global variables in C language have the same name (when local variables and global variables exist at the same time, local variables are preferred to be refer
- Compression and decompression commands
- The white paper on the panorama of the digital economy and the digitalization of consumer finance were released
- Design of secsha system
猜你喜欢

CSDN salary increase technology selenium automated test stack summary

Markdown Mermaid planting grass (1)_ Introduction to Mermaid

阿里开源(EasyExcel)

Bayesian inference problem, MCMC and variational inference

Xiaobai's e-commerce business is very important to choose the right mall system!

2022茶艺师(中级)考试模拟100题及模拟考试

数字经济专家高泽龙:映客更名映宇宙,元宇宙会成为映客下一个增长引擎吗?

30讲 线性代数 第四讲 线性方程组

Variable autoencoders (vaes)
![return new int[]{i + 1, mid + 1}; return {i + 1, mid + 1};](/img/6a/45a4494276deba72ef9833818229f5.png)
return new int[]{i + 1, mid + 1}; return {i + 1, mid + 1};
随机推荐
2022焊工(初级)特种作业证考试题库及答案
easypoi
论文阅读:Duplex Contextual Relation Network for Polyp Segmentation
30讲 线性代数 第四讲 线性方程组
return new int[]{i + 1, mid + 1};return {i + 1, mid + 1};
蓝桥杯 历届试题 蚂蚁感冒
Tencent tangdaosheng: facing the new world of digital and real integration, developers are the most important "architects"
计网 | 一文解析TCP协议所有知识点
Gaozelong, a digital economy expert: Yingke changed its name to yingcosmos. Will yuancosmos become the next growth engine of Yingke?
TcWind 模式设定
C # application interface development foundation - form control
grep文本搜索工具
How to obtain the coordinates of the aircraft passing through both ends of the radar
2280.Cupboards
Priority problem when local variables and global variables in C language have the same name (when local variables and global variables exist at the same time, local variables are preferred to be refer
Paper notes: universal value function approvers
Bayesian inference problem, MCMC and variational inference
ROS中quaternion四元数和欧拉角转换
From design delivery to development, it is easy and efficient!
Quaternion quaternion and Euler angle transformation in ROS