mash alyy

mash alyy

  • NA
  • 12
  • 6.8k

Delete particular record by checking records in access db 2007

Jul 29 2012 2:41 AM
Hi.

I want to delete a particular record from the access db 2007, the below code is working fine but whether record existing or not its just saying record deleted.
But I don't want that, It shud check whether record exists or not, if exist then shud delete the record otherwise shud say "No record found".

My code::
 Dim con As OleDbConnection
        Dim com As OleDbCommand
        con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Environment.CurrentDirectory & "\MQIB.mdb")
        com = New OleDbCommand("delete from Books where BookSerial =@bsno", con)
        con.Open()
        com.Parameters.AddWithValue("@bsno", Integer.Parse(txtBS.Text))
        com.ExecuteNonQuery()
        MsgBox("Record Deleted")
        con.Close()

Plz help me out.