时间:2021-07-01 10:21:17 帮助过:2人阅读
//删:delete SqlConnection con = new SqlConnection("server=.; database=ADO; user=sa; pwd=ray;"); string sql = "delete from Student where Sname=‘钱八‘"; using (SqlCommand cmd = new SqlCommand(sql, con)) { con.Open(); int s = cmd1.ExecuteNonQuery(); Console.WriteLine("成功删除了{0}行数据\n" + sql, s); con.Close(); Console.ReadKey(); }
//(3)改:update...set SqlConnection con = new SqlConnection("server=.; database=ADO; user=sa; pwd=ray;"); string sql = "update Student set Sname=‘张小三‘,Sbirthday=‘2000-01-01‘,Sscore=100 where Scode=10001"; using (SqlCommand cmd=new SqlCommand(sql,con)) { con.Open(); int g = cmd.ExecuteNonQuery(); Console.WriteLine("成功更改了{0}行数据\n"+sql,g); con.Close(); Console.ReadKey(); }
//(4)查:select
SqlConnection con = new SqlConnection("server=.; database=ADO; user=sa; pwd=ray;"); string sql = "select count(*) from Student"; using (SqlCommand cmd=new SqlCommand(sql,con)) { con.Open(); object c=cmd.ExecuteScalar(); Console.WriteLine("Student表中共有{0}条数据",c); con.Close(); Console.ReadKey(); }
Chapter 1. Ado.Net 数据库增删改查
标签: