Click here to Skip to main content
11,428,221 members (62,431 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: Access VB.NET
Dim RouteID As String
 Dim Response As Integer
        RouteID = InputBox("Enter the Route ID of the record to be deleted ")
        If RouteID <> And Not Regex.IsMatch(RouteID, "[a-z]") Then
            ' Displays a message box with the yes and no options.

            Response = MsgBox(Prompt:="NOTE: Are you sure ?" & vbCrLf & "Deleting this record will erase data from database", Buttons:=vbYesNo)
            ' If statement to check if the yes button was selected.
            If Response = vbYes Then
                con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\jai shri krishna\My Documents\Busmanagement.mdb")

                str = "DELETE FROM RouteDetails WHERE RouteID = '" + RouteID + "'"
                cmdDelete = New OleDbCommand(str, con)
                cmdDelete.ExecuteNonQuery()' getting error datatype mismatch in criteria expression 
                MsgBox("Record Deleted")
Posted 12-Apr-13 12:01pm
Edited 12-Apr-13 12:02pm
richcb at 12-Apr-13 17:03pm
You probably want RouteID to be an int. Then remove the ' ' from your Delete statement that surrounds the RouteID in your Where clause.
Polarfuze at 12-Apr-13 18:35pm
Thank you that helped
richcb at 15-Apr-13 13:55pm
You are welcome.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If ID is numeric value (not text), use

str = "DELETE FROM RouteDetails WHERE RouteID = " & RouteID 

To concatenate strings in VB.NET use "&" instead of "+"

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

Advertise | Privacy | Mobile
Web01 | 2.8.150428.2 | Last Updated 12 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100