Data type mismatch in criteria expression. can help Mee RRS feed

  • Question

  • User-2007781415 posted

    this the code

    and the error

    Data type mismatch in criteria expression.


    Public Sub insert(ByVal StudentID As Single, ByVal ArticleNo As Single, ByVal DivisionNo As Single, ByVal ArticleName As String, ByVal NumOfHours As Integer, ByVal TeacherName As String, ByVal Days As String, ByVal Time As String, ByVal Place As String)
            If con.State = ConnectionState.Closed Then
            End If
            Dim adp As New OleDb.OleDbCommand("insert into  Stat values (" & getmaxid() & "," & StudentID & "," & ArticleNo & "," & DivisionNo & ",'" & ArticleName & "'," & NumOfHours & ",'" & TeacherName & "','" & Days & "','" & Time & "','" & Place & "')", con)




    Sunday, March 13, 2011 2:19 PM


All replies

  • User-821857111 posted

    Are Days and Time really strings in the database? You can save yourself a lot of these types of problems by using parameters: Parameter Queries in ASP.NET with MS Access

    What's getmaxid?


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 13, 2011 3:07 PM
  • User1867929564 posted

    yes you should use parameter query.

    Secondly if column datatype is numric/int then single quote not require else it is required.
    check if you are passing any null. 

    Monday, March 14, 2011 2:12 AM
  • User3866881 posted

    This error means that:

    1) if your column type is something of int, long or…… type of numeric, you shouldn't add single quote to do insert in sql statement.

    2) If type of char/varchar……something related to string, you should add single quote to include the contents.

    Just like what mvp means, you should use strongly parameterized things instead of your string splits combination. Or SQL injection will happen.

    Monday, March 14, 2011 10:21 PM