I am trying to delete a row with the patient name Mike.
When click on the command the error says: Object Reference not set to an instance of an object
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sqlconnectionstring As String = "Data Source=Server;User ID=admin;Password=lalala;Persist Security Info=False;Initial Catalog=Oasis"
Dim SqlConn As New System.Data.SqlClient.SqlConnection(sqlconnectionstring)
Dim strTrackingSheet As String = "Select * from Trackingsheet"
Dim datrackingsheet As New System.Data.SqlClient.SqlDataAdapter(strTrackingSheet, sqlconnectionstring)
Dim dsPatient As New System.Data.DataSet
Dim strSQL1 As String = "DELETE FROM Trackingsheet WHERE First = Mike"
Try
SqlConn.Open()
datrackingsheet.DeleteCommand.CommandText = strSQL1
datrackingsheet.DeleteCommand.ExecuteNonQuery()
Catch exceptionObject As Exception
MessageBox.Show(exceptionObject.Message)
Finally
SqlConn.Close()
End Try
End Sub
Any suggestions?
When click on the command the error says: Object Reference not set to an instance of an object
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sqlconnectionstring As String = "Data Source=Server;User ID=admin;Password=lalala;Persist Security Info=False;Initial Catalog=Oasis"
Dim SqlConn As New System.Data.SqlClient.SqlConnection(sqlconnectionstring)
Dim strTrackingSheet As String = "Select * from Trackingsheet"
Dim datrackingsheet As New System.Data.SqlClient.SqlDataAdapter(strTrackingSheet, sqlconnectionstring)
Dim dsPatient As New System.Data.DataSet
Dim strSQL1 As String = "DELETE FROM Trackingsheet WHERE First = Mike"
Try
SqlConn.Open()
datrackingsheet.DeleteCommand.CommandText = strSQL1
datrackingsheet.DeleteCommand.ExecuteNonQuery()
Catch exceptionObject As Exception
MessageBox.Show(exceptionObject.Message)
Finally
SqlConn.Close()
End Try
End Sub
Any suggestions?