Results 1 to 6 of 6

Thread: [2008] Data type mismatch in criteria expression. [SQL with ACCESS]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    258

    [2008] Data type mismatch in criteria expression. [SQL with ACCESS]

    Error: Data type mismatch in criteria expression.

    Code:

    vb Code:
    1. With frmMainMenu
    2.             Dim SLen As Integer = Len(.lblCourse.Text)
    3.             SLen = SLen - 8
    4.             Dim BirthDate As String
    5.             Dim GenderChk As String
    6.             BirthDate = .txtMonth.Text & "/" & .txtDay.Text & "/" & .txtYear.Text
    7.             If .rbMale.Checked = True Then
    8.                 GenderChk = "Male"
    9.             ElseIf .rbFemale.Checked = True Then
    10.                 GenderChk = "Female"
    11.             End If
    12.             SQL = "INSERT INTO Course_" & .lblCourse.Text.ToCharArray(8, SLen) & " (LastName, FirstName, Gender, HomeRoom, StudentNumber, BirthDate, PhoneNumber, StudentEmail, ParentsEmail) VALUES('" & .txtLastName.Text & "','" & .txtFirstName.Text & "','" & GenderChk.ToString() & "','" & .txtHomeRoom.Text & "','" & .txtStudentNumber.Text & "','" & BirthDate.ToString() & "','" & .txtPhoneNumber.Text & "','" & .txtEmail.Text & "','" & .txtParentsEmail.Text & "')"
    13.             Command = New OleDbCommand(SQL, Connection)
    14.             Command.Connection.Open()
    15.             Command.ExecuteReader()
    16.             Command.Connection.Close()
    17.         End With

    Mainly This Part:
    vb Code:
    1. SQL = "INSERT INTO Course_" & .lblCourse.Text.ToCharArray(8, SLen) & " (LastName, FirstName, Gender, HomeRoom, StudentNumber, BirthDate, PhoneNumber, StudentEmail, ParentsEmail) VALUES('" & .txtLastName.Text & "','" & .txtFirstName.Text & "','" & GenderChk.ToString() & "','" & .txtHomeRoom.Text & "','" & .txtStudentNumber.Text & "','" & BirthDate.ToString() & "','" & .txtPhoneNumber.Text & "','" & .txtEmail.Text & "','" & .txtParentsEmail.Text & "')"

    I used
    vb Code:
    1. .lblCourse.Text.ToCharArray(8, SLen)

    Because I wanted to get the text that appeared after a certain piece of text which then defines the table I'm in.

    If I can't use .ToCharArray, what can I do to split the text into 2, and use the last half?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2008] Data type mismatch in criteria expression. [SQL with ACCESS]

    .lblCourse.Text.substring(index of first character you want)

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    258

    Re: [2008] Data type mismatch in criteria expression. [SQL with ACCESS]

    I'm still getting the same error with this SQL String

    vb Code:
    1. SQL = "INSERT INTO Course_" & .lblCourse.Text.Substring(8) & " (LastName, FirstName, Gender, HomeRoom, StudentNumber, BirthDate, PhoneNumber, StudentEmail, ParentsEmail) VALUES('" & .txtLastName.Text & "','" & .txtFirstName.Text & "','" & GenderChk.ToString() & "','" & .txtHomeRoom.Text & "','" & .txtStudentNumber.Text & "','" & BirthDate.ToString() & "','" & .txtPhoneNumber.Text & "','" & .txtEmail.Text & "','" & .txtParentsEmail.Text & "')"

    IT then highlights

    Command.ExecuteReader()

  4. #4
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: [2008] Data type mismatch in criteria expression. [SQL with ACCESS]

    I think

    Code:
    GenderChk.toString
    should be
    Code:
    GenderChk.Checked
    Edit: Without Single Quote (')

    Also you should have used
    Code:
    Command.ExecuteNonQuery()
    Last edited by riteshjain1982; Sep 12th, 2008 at 04:57 PM.
    __________________
    Rate the posts that helped you

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    258

    Re: [2008] Data type mismatch in criteria expression. [SQL with ACCESS]

    Can someone explain what Command.ExecuteReader and Command.ExecuteNonQuery Do? Whats the Difference?

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    258

    Re: [2008] Data type mismatch in criteria expression. [SQL with ACCESS]

    Edit: I tried both - tried removing GenderChk (which is a variable to check if its a male or female) but I'm still getting the error:

    Heres my new Code

    vb Code:
    1. Public Sub InsertIntoStudents()
    2.         With frmMainMenu
    3.             Dim BirthDate As String
    4.             Dim GenderChk As String
    5.             BirthDate = .txtMonth.Text & "/" & .txtDay.Text & "/" & .txtYear.Text
    6.             If .rbMale.Checked = True Then
    7.                 GenderChk = "Male"
    8.             ElseIf .rbFemale.Checked = True Then
    9.                 GenderChk = "Female"
    10.             End If
    11.             Dim i As String = .lblCourse.Text.Substring(8)
    12.             SQL = "INSERT INTO Course_ICS3M1" & " (LastName, FirstName, HomeRoom, StudentNumber, BirthDate, PhoneNumber, StudentEmail, ParentsEmail) VALUES('" & .txtLastName.Text & "','" & .txtFirstName.Text & "','" & .txtHomeRoom.Text & "','" & .txtStudentNumber.Text & "','" & BirthDate & "','" & .txtPhoneNumber.Text & "','" & .txtEmail.Text & "','" & .txtParentsEmail.Text & "')"
    13.             Command = New OleDbCommand(SQL, Connection)
    14.             Command.Connection.Open()
    15.             Command.ExecuteNonQuery()
    16.             Command.Connection.Close()
    17.         End With
    18.     End Sub


    All Fields are filled in on the forum.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width