我需要保存在運行時輸入的數據。我怎麼做?我嘗試了很多代碼。我的代碼中沒有出現任何錯誤,但是當我退出並檢查數據表時,數據不存在於數據庫中。需要使用vb8 express在sql數據庫中保存數據
這裏是我的代碼:
Dim con As New SqlClient.SqlConnection
Dim cmd As New SqlClient.SqlCommand
Try
con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\ClubDatabase.mdf;Integrated Security=True;User Instance=True"
con.Open()
cmd.Connection = con
cmd.CommandText = "INSERT INTO Liquor([Product ID], [Name], [Quantity], [Cost Price], [Selling Price]) VALUES('" & Product_IDTextBox.Text & "','" & NameTextBox.Text & "','" & QuantityTextBox.Text & "','" & Cost_PriceTextBox.Text & "','" & Selling_PriceTextBox.Text & "')"
cmd.ExecuteNonQuery()
MessageBox.Show("added")
Catch ex As Exception
MessageBox.Show("Error while inserting record on table..." & ex.Message, "Insert Records")
Finally
con.Close()
End Try
您查詢是容易的'SQL injection'。 – spajce 2013-02-16 17:31:04