Hi everyone
i am trying to save the data from the text boxes on my form to my sql database but im not having any luck please can someone help me?
ive simply got 4 text boxes and a save button the code for my save button is as follows.
It just bring up an error, i thought this would be simple but for me its proving not to be at all.
thanks Roo
i am trying to save the data from the text boxes on my form to my sql database but im not having any luck please can someone help me?
ive simply got 4 text boxes and a save button the code for my save button is as follows.
VB.NET:
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
It just bring up an error, i thought this would be simple but for me its proving not to be at all.
thanks Roo
Last edited: