Click here to Skip to main content
15,943,335 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can someone tell me what's wrong with this code? The record in database won't be deleted. It always shows the message box that the record is failed to delete. I hope someone can help me with this. Please do respect my question. Thankyou.

I'm using MS ACCESS DATABASE and VB.NET

What I have tried:

Private Sub deletebtn_Click(sender As Object, e As EventArgs) Handles deletebtn.Click

If (MessageBox.Show("Are you sure you want to delete this record?", "TIPAS FOODCOURT KIOSK", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then

Try


conn.Open()
Dim cmd As New OleDb.OleDbCommand("DELETE FROM `tblaccts1` WHERE `StoreCODE`=[@STORE CODE]", conn)
Dim i As New Integer
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("@StoreCODE", storeCode.Text)
cmd.ExecuteNonQuery()

If i > 0 Then
MessageBox.Show("YOUR RECORD IS SUCCESFULLY DELETED", "TIPAS FOODCOURT KIOSK", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("YOUR RECORD IS FAILED TO DELETE", "TIPAS FOODCOURT KIOSK", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If

Catch ex As Exception
MsgBox(ex.Message)
End Try
conn.Close()
DGV_load()
DASHBOARD.imageload()

End If


End Sub
Posted
Updated 7-Nov-22 20:56pm
v2

1 solution

Remove the "[" and "]" around the parameter name, and make sure the two parameter names match up:
"DELETE FROM tblaccts1 WHERE StoreCODE = @StoreCODE"
cmd.Parameters.AddWithValue("@StoreCODE", storeCode.Text)
 
Share this answer
 
Comments
Hazel Ann Torno 2022 8-Nov-22 4:17am    
It still not working. :<
OriginalGriff 8-Nov-22 4:43am    
Then use the debugger to find out exactly what is in the textbox.
Then use Access to run your query and check how many matching rows there are.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900