string strConnection = "Persist Security Info=False;Integrated Security=SSPI;database= cardread;server= (local)\\mssmlbiz;Connect Timeout=30";
SqlConnection objConnection = new SqlConnection(strConnection);
objConnection.Open();
1.
string name = "";
string delegeSql = "insert into data_card(data) values(@Name)";
//SqlCommandBuilder thisBuilder = new SqlCommandBuilder(SDA);
//Console.WriteLine(SDA.SelectCommand.CommandText);
SqlParameter para = new SqlParameter("@name", SqlDbType.NVarChar, 16);
para.Value = name;
strComm.Parameters.Add(para);
SqlDataAdapter SDA = new SqlDataAdapter(delegeSql, strConnection);
SqlCommand strComm = new SqlCommand(delegeSql, objConnection);
strComm.ExecuteNonQuery();
2.
string name = "";
string delegeSql = "insert into data_card values('" + name.Substring(0,16) + "')";
SqlDataAdapter SDA = new SqlDataAdapter(delegeSql, strConnection);
SqlCommand strComm = new SqlCommand(delegeSql, objConnection);
strComm.ExecuteNonQuery();
2中方法可以执行sql语句.
阅读(1563) | 评论(0) | 转发(0) |