Thanks for the quick relpy
i have dont that and the error message that comes up now says: "Object Reference not set to an instance of an object" ? so now my code looks as follows :
any ideas on how to resolve this?Code: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) InsertCommand.Prepare() 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




Reply With Quote