class Program { static void Main(string[] args) { //连接数据库 using (MySqlConnection conn = new MySqlConnection("Server=127.0.0.1;Database=study;uid=root;pwd=root;Charset=utf8")) //创建Mysql对象 using (MySqlCommand cmd = conn.CreateCommand()) { conn.Open();//打开数据库 //赋值sql语句 cmd.CommandText = "INSERT INTO t_customers(name,age) values(‘小胖妞‘,22)"; //执行sql语句,返回受影响的行数 int r = cmd.ExecuteNonQuery(); Console.WriteLine("插入成功"+r); Console.ReadKey(); } } }
时间: 2024-10-12 23:25:06