Best OLEDB Delete Command Vb.Net Code Example vb.net

This post is about the code for OLEDB delete command vb.net. Used to delete records in an Access database.

OLEDB Delete Command Vb.Net Code Example

1#. To delete any record use the below code for oledb delete command.

Try 
  Dim cmd As New OleDbCommand("Delete * from " & TableName & " where ID = " & txtIDNumber.Text & "", conn) 
  ConnectOledb() 
  cmd.ExecuteNonQuery() 
 DisConnectOledb()
  MsgBox("Record No:" & txtIDNumber.Text & " Deleted Successfully") 
Catch ex As Exception
  MsgBox("Delete Error : " & ex.Message)
End Try

2#. To delete any record use the below code for oledb delete command.

        Try
            ConnectOledb()
            Dim cmd As New OleDbCommand("delete from " & TableName & " where ID=" & ID_No & "", conn)
            cmd.ExecuteNonQuery()
            DisConnectOledb()
            MessageBox.Show("Record ID Number : " & ID_No, "Deleted Successfully", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End Try

Leave a Comment