Can anyone help me with deleting the row from the DB using OleDb?
Expand|Select|Wrap|Line Numbers
- Function DeleteTableRow()
- Dim TaxConnStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ConfigurationManager.AppSettings("Database")
- Dim dbConnection = New OleDbConnection(TaxConnStr)
- Try
- Dim dbCommand As OleDbCommand = New OleDbCommand
- Dim rdr2 As OleDbDataReader
- Dim selectedRow = DataGridView1.SelectedRows
- dbCommand.CommandText = "DELETE FROM UserCriteria WHERE RowID =" & selectedRow
- If dbConnection.State = ConnectionState.Closed Then
- dbConnection.Open()
- End If
- dbCommand.Connection = dbConnection
- rdr2 = dbCommand.ExecuteReader
- dbCommand.ExecuteNonQuery()
- rdr2.Close()
- '''allows you to select on cell in the row to delete entire row
- For Each oneCell As DataGridViewCell In DataGridView1.SelectedCells
- If oneCell.Selected Then
- DataGridView1.Rows.RemoveAt(oneCell.RowIndex)
- End If
- Next
- Catch ex As Exception
- MsgBox(ex.Message)
- Finally
- dbConnection.Close()
- End Try
- End Function