
Originally Posted by
jumper77
Good morning all. New milestone. I now have the 'DeleteRow' method working.
Code:
Private Sub deleteRow()
Dim DeleteString As String = "delete from customer where rowID = " & dgvCustomer.CurrentRow.Cells(0).Value.ToString()
Using command As SQLiteCommand = db.CreateConnection.CreateCommand()
command.CommandText = DeleteString
Dim result As Integer = command.ExecuteNonQuery()
End Using
da.Update(dt)
RefreshData()
End Sub
If your using a dgv then there's an easier way
Code:
Private Sub DeleteButton_Click(sender As System.Object, e As System.EventArgs) Handles DeleteButton.Click
If Me.DataGridView1.SelectedRows.Count > 0 Then
'you may want to add a confirmation message, and if the user confirms delete
Me.DataGridView1.Rows.Remove(Me.DataGridView1.SelectedRows(0))
Else
MessageBox.Show("Select 1 row before you hit Delete")
End If
End Sub
Just click on the dgv row header (far left column) to highlight the row. Then click the delete button.
Actually, you don't even need a Delete Button. If you Highlight a row and press the Keyboard Delete key, it will delete the row.
Remember you have to save your changes.