我想將某些文本框的內容插入到SQL Server數據庫中。SQL Server INSERT命令不會插入數據
這是我的代碼使用方法:
SqlConnection myConn = new SqlConnection(myConnection);
myConn.Open();
SqlCommand InsertCommand = new SqlCommand("INSERT INTO invmgmt.Products (product_id, product_name, product_price, possible_discount, product_in_stock) VALUES ('" + Convert.ToInt32(tbAddProdID.Text) + "','" + tbAddProdName.Text + "','" + Convert.ToDouble(tbAddProdPrice.Text) + "','" + Convert.ToInt32(tbAddPblDiscount.Text) + "','" + Convert.ToInt32(tbAddInStock.Text) + "')");
myConn.Close();
如果我是執行,沒有任何反應到數據庫中,沒有人知道該怎麼辦?我試過其他一些Insert
命令,但沒有想要工作。
+1的secound參數。字符串連接已廣泛開放給http://en.wikipedia.org/wiki/SQL_injection。 – Matt 2014-08-29 19:38:14