unable to delete but the row was deleted

alreakemz

New member
Joined
Jan 14, 2011
Messages
3
Programming Experience
Beginner
Dim strDelete, sqlDetect As String
strDelete = InputBox("Please enter valid Borrower's ID to delete", "Delete")
open_con()


cmd = New OleDbCommand("DELETE FROM tblBorrower WHERE bor_id LIKE '" & strDelete & "'", con)
dr = cmd.ExecuteReader
If dr.Read() Then
If strDelete = dr("bor_id") Then
cmd.ExecuteNonQuery()
MsgBox("Item deleted", MsgBoxStyle.Information, "Delete Success")
Else
MsgBox("Unable to delete", MsgBoxStyle.Exclamation, "Message")

End If
End If
If strDelete <> dr("bor_id") Then
MsgBox("Item not found or item not exist", MsgBoxStyle.Exclamation, "Delete Error")
End If
dr.Close()
cmd = Nothing
con.Close()

my question is:

i want to delete the row or data in database mysql2000,but when i delete press delete it says unable to delete but the row was deleted... any idea plz... i need help really badly... can you correct my codes sir and show me the correct codes if you may... sorry for my bad english... hope you help me out...
 
Please provide meaningful titles for your threads. The point of the title is to let us know what the thread is about without our having to open it. Lots of threads are created every day and every one is asking for help. If we have to open every one to find out what they're about then it's a waste of our time. Do as much as you can to help those whom you would like to help you.

As for the question, you shouldn't be calling ExecuteReader to delete a record. ExecuteReader is for reading data, i.e. executing a SELECT query. If you're executing a DELETE statement then you should be calling ExecuteNonQuery. It will return the number of records affected by the command. Zero means nothing was changed and anything else means data was deleted.
 
As I said, the result of ExecuteNonQuery will tell you whether the record was found or not. A return value of 0 means that no records were deleted. Get rid of the ExecuteReader line.
 
Back
Top