Hi
I am currently puting together a data driven application just for fun and to get to know sql. The problem i am having is on my new customer form i can not get the data in my text boxes to save into my database table at runtime.
I simply have 4 textboxes and a save button the code for my save button is as follows:
All this does is bring up an error in runtime please can someone help me fix this so that when i press save the details in my text boxes are actually saved into my database tableCode:Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Dim Connection As SqlConnection = MSDB.GetConnection Dim mySqlCommand As SqlCommand = New SqlCommand Connection.Open() mySqlCommand.Connection = Connection Try mySqlCommand.CommandText = "INSERT INTO customers (CustomerID, Customer, Contact, Email) VALUES ('@CustomerID', '@Customer', '@Contact', '@Email')" Dim InsertCommand As SqlCommand = New SqlCommand InsertCommand.Parameters.AddWithValue("@CustomerID", tbCustomerID.Text) InsertCommand.Parameters.AddWithValue("@Customer", tbCustomer.Text) InsertCommand.Parameters.AddWithValue("@Contact", tbContact.Text) InsertCommand.Parameters.AddWithValue("@Email", tbEmail.Text) mySqlCommand.ExecuteNonQuery() MessageBox.Show("New Customer Added To Your Database") Catch ex As Exception MessageBox.Show("Customer could not be added!" & ex.Message) Finally If Connection.State = ConnectionState.Open Then Connection.Close() End If End Try End Sub
Thanks Roo




Reply With Quote