Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Code: Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As Syst

ID: 3548871 • Letter: C

Question

Code:


    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click

        Dim Str As String
        If CheckId() = False Then
            MsgBox("Id : Integer Value Required!!!")
            Exit Sub
        End If
        Try
            Str = "delete from CRIMINAL where CriminalID=?"
            Str += txtCID.Text.Trim
            Con.Open()
            Cmd = New OleDbCommand(Str, Con)
            Cmd.ExecuteNonQuery()
            Dst.clear()
            Dad = New OleDbDataAdapter("SELECT * FROM CRIMINAL ORDER BY CriminalID", Con)
            Dad.Fill(Dst, "CRIMINAL")
            MsgBox("Record deleted successfully...")
            If CurrentRow > 0 Then
                CurrentRow -= 1
                ShowData(CurrentRow)
            End If
            Con.Close()
        Catch ex As Exception
            MessageBox.Show("Could Not delete Record!!!")
            MsgBox(ex.Message & " -  " & ex.Source)
            Con.Close()
        End Try

    End Sub


Occur error image:


  


Please help me solve my error.

Syntax error (missing operator) in query expression 'CriminalID=?1001'. -Microsoft Access Database Engine

Explanation / Answer

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click

Dim Str As String
If CheckId() = False Then
MsgBox("Id : Integer Value Required!!!")
Exit Sub
End If
Try

Str = "delete from CRIMINAL where CriminalID='"
            Str += txtCID.Text.Trim + "'"
            MsgBox(Str)
            Con.Open()
            Cmd = New OleDbCommand(Str, Con)
            Cmd.ExecuteNonQuery()

Dst.clear()
Dad = New OleDbDataAdapter("SELECT * FROM CRIMINAL ORDER BY CriminalID", Con)
Dad.Fill(Dst, "CRIMINAL")
MsgBox("Record deleted successfully...")
If CurrentRow > 0 Then
CurrentRow -= 1
ShowData(CurrentRow)
End If
Con.Close()
Catch ex As Exception
MessageBox.Show("Could Not delete Record!!!")
MsgBox(ex.Message & " - " & ex.Source)
Con.Close()
End Try

End Sub