i need to be able to delete a row and its content via a datagrid viewer, the current code i have written only deletes the contents of row 0 and i cannot get it to do so at a selected row.
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Dim dataAdapter As New OleDbDataAdapter
Dim DataTable As New DataTable
Dim DataSet As New DataSet
Try
DataSet.Tables.Add(DataTable)
Connection.Open()
dataAdapter = New OleDbDataAdapter("SELECT * FROM Students", Connection)
dataAdapter.Fill(DataTable)
DataTable.Rows(0).BeginEdit()
DataTable.Rows(0).Delete()
DataTable.Rows(0).EndEdit()
Dim Commandbuilder As New OleDbCommandBuilder(dataAdapter)
dataAdapter.Update(DataTable)
dgrStudentDatabaseViewer.DataSource = DataTable.DefaultView
Connection.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Connection.Close()
End Try
End Sub
Thanks in advance.
DataTable.Rows(0).Delete()you have it hardcoded to delete row(0)