SqlConnection mycnn;
SqlCommand mycomd;
mycnn = new SqlConnection("server=localhost;database=Northwind;uid=sa;pwd=;");
string insertCmd="insert into orders(name) values(@name)";//字段最好不要取名为Name,改改先!因为和SQL保留的关键字冲突
mycomd=new SqlCommand(insertCmd,mycnn);
mycomd.Parameters.Add(new SqlParameter("@name",SqlDbType.VarChar,50));
mycomd.Parameters["@name"].Value="ccc";
SqlCommand mycomd;
mycnn = new SqlConnection("server=localhost;database=Northwind;uid=sa;pwd=;");
string insertCmd="insert into orders(name) values(@name)";//字段最好不要取名为Name,改改先!因为和SQL保留的关键字冲突
mycomd=new SqlCommand(insertCmd,mycnn);
mycomd.Parameters.Add(new SqlParameter("@name",SqlDbType.VarChar,50));
mycomd.Parameters["@name"].Value="ccc";
SqlCommand mycomd;
mycnn = new SqlConnection("user id=sa;password='123';initial
catalog=Northwind");
mycomd.Connection.Open();//
string insertCmd="insert into orders(name) values(@name)";
mycomd=new SqlCommand("insert into orders(name) values(@name)",mycnn);
mycomd.Parameters.Add(new SqlParameter("@name",SqlDbType.VarChar,50));
mycomd.Parameters["@name"].Value="ccc";把mycomd.Connection.Open();// 提前
mycnn = new SqlConnection("user id=sa;password='123';initial
catalog=Northwind");
中连接串有错。
改为
mycnn = new SqlConnection("server=localhost;database=Northwind;uid=sa;pwd=123;");