i create a form that can save data in sql..now i want to delete the data that appear in the text box that i'have created earlier...the problem is the data wont be deleted...i tryto fix the error but it wont do anygood can u guys help me with this prob....this is the error mistake that appear...
line that the error occur- 'varAdapter.DeleteCommand = varCommand'
An unhandled exception of type 'System.NullReferenceException' occurred in ROP1.exe
Additional information: Object reference not set to an instance of an object.
CODE
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim varAdapter As SqlDataAdapter
If MessageBox.Show("Do you really want to delete this record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then
MsgBox("Operation cancelled")
Exit Sub
End If
varConnection = New SqlConnection("Server=(local);user id=sa;password=;Initial Catalog=ROP1") 'STEP 1
varConnection.Open() 'STEP 2
varQuery = "DELETE FROM tbl_rop WHERE Name_User ='" & Trim(TextBox1.Text) & "', Date_of_birth= '" & Trim(TextBox2.Text) & "' , Hobbies='" & Trim(TextBox3.Text) & "' , Phone_Number ='" & Trim(TextBox4.Text) & "' where Name_User = '" & Trim(TextBox1.Text) & "'" 'STEP 3
varCommand = New SqlCommand(varQuery, varConnection)
varAdapter.DeleteCommand = varCommand
varAdapter.UpdateCommand = varUpdateCommand
varCommand.ExecuteNonQuery()
varCommand.Dispose() 'STEP 6
varConnection.Close() 'STEP 7
varAdapter.Update(varDataSet)
End Sub
This post has been edited by gabanxx: 2 Jun, 2008 - 07:47 PM