C#向SQLServer數據庫中插入數據,沒有反應,代碼如下:
string conn, sql, strxm,strxh,strxb,strlxfs;
strxm = textBox1.Text;
strxh = textBox2.Text;
strxb = textBox3.Text;
strlxfs = textBox4.Text;
conn = "Server=.;Database=13rj;Trusted_Connection=SSPI";
//conn = "Server=(local);Database=13rj;uid=sa;pwd=59634";
sql = "insert into rj13_basic(xm,xh,xb,lxfs) values("+ strxm + "," + strxh +","+strxb+","+strlxfs+")";
SqlConnection myconn = new SqlConnection(conn);
myconn.Open();
SqlDataAdapter myda = new SqlDataAdapter(sql, conn);
//DataSet myds = new DataSet();
//myda.Fill(myds, "rj13_basic");
myconn.Close();
不可能沒有報錯,同時沒有插入的。
先去掉 try catch,如果代碼執行了,沒有插入數據,那麼再看你插入數據的表和你看的表是不是一個表,是不是一個庫。