本帖最后由 丁官林 于 2012-4-22 06:57 编辑
我是ADO.NET初学者,请大侠帮忙解释一下这两段代码的区别和联系
下面这段是书上的写法:
string str=@"Data Source=.\SQLEXPRESS;Initial Catalog=myDb;User ID=sa";
SqlConnection conn = new SqlConnection(str);
conn.Open();
String sql = "insert into userInfo values('admin','12345')";
SqlCommand cmd = new SqlCommand(sql,conn);
cmd.ExecuteNonQuery();
下面这段:视频里的写法
string str=@"Data Source=.\SQLEXPRESS;Initial Catalog=myDb;User ID=sa";
SqlConnection conn = new SqlConnection(str);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "insert into userInfo values('admin','123456')";
cmd.ExecuteNonQuery();
|