我需要保存在运行时输入的数据。我怎么做?我尝试了很多代码。我的代码中没有任何错误,但是当我退出并检查我的数据表时,数据库中不存在数据。
这是我的代码:
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