SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Server=; Database=; User id=; password=";
conn.Open();
string Query = "Insert into [Capstone0480].[dbo].[NAME] (NameID, FirstName, MI, LastName, UserID) Values('" + this.txtNameID.Text + "','" + txtFirst.Text + "','" + txtMI.Text + "','" + txtLast.Text + "', '" + txtUserID.Text + "')";
SqlCommand createCommand = new SqlCommand(Query, conn);
createCommand.ExecuteNonQuery();
MessageBox.Show("Updated");
conn.Close();
我在ExecuteNonQuery()
聲明中收到此錯誤。我不確定這裏有什麼問題。我覺得我的sql語句是正確的。我只是試圖將輸入到文本框中的內容添加到我的數據庫中。字符串或二進制數據將被截斷。 C語言中的SQL語句#
如果有更好的方法來做到這一點,或者如果有什麼問題,請讓我知道!
你的一個文本框的
良好包含的字符串太長了其在數據庫列。 – Blorgbeard 2014-11-24 04:16:24
「NameID」,「FirstName」,「MI」,「LastName」和「UserID」列的類型是什麼? 「txtNameID.Text」,「txtFirst.Text」,「txtMI.Text」,「txtLast.Text」和「txtUserID.Text」的價值是什麼? – ekad 2014-11-24 04:17:27
與您的問題沒有關係,但您添加參數的方式不適合。 [看到這個](http://stackoverflow.com/questions/4624811/different-ways-of-passing-sqlcommand-parameters)。如果你需要幫助,我可以解釋更多。 – techvice 2014-11-24 04:32:34