Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Data type mismatch in criteria expression.

Data type mismatch in criteria expression.

Scheduled Pinned Locked Moved Visual Basic
helpdatabasebeta-testingcode-review
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    peteyshrew
    wrote on last edited by
    #1

    i am trying to read a number from an access table check it and use it to control access to another page. this is the code snippet where i think the problem is and the feedback i'm getting is saying this "Data type mismatch in criteria expression" - referring to the highlighted line of code below. Dim PinNumber As String PinNumber = "SELECT DISTINCT Pin FROM Accounts WHERE Pin='" & Me.tbPin.Text & "'AND AccountID = '" & Me.tbID.Text & "'" comm.CommandText = PinNumber 'the variable is declared as a command dr = comm.ExecuteReader 'gives the variable a value If dr.Read() Then 'if the entry is correct (readable) Form2.Show() 'show the index varibale (form) Me.Close() 'close the current form Else 'if the entry is incorrect MessageBox.Show("Invalid Pin, please try again") 'displays error message tbPin.Clear() 'clears the managerid tbID.Clear() End If

    C R 2 Replies Last reply
    0
    • P peteyshrew

      i am trying to read a number from an access table check it and use it to control access to another page. this is the code snippet where i think the problem is and the feedback i'm getting is saying this "Data type mismatch in criteria expression" - referring to the highlighted line of code below. Dim PinNumber As String PinNumber = "SELECT DISTINCT Pin FROM Accounts WHERE Pin='" & Me.tbPin.Text & "'AND AccountID = '" & Me.tbID.Text & "'" comm.CommandText = PinNumber 'the variable is declared as a command dr = comm.ExecuteReader 'gives the variable a value If dr.Read() Then 'if the entry is correct (readable) Form2.Show() 'show the index varibale (form) Me.Close() 'close the current form Else 'if the entry is incorrect MessageBox.Show("Invalid Pin, please try again") 'displays error message tbPin.Clear() 'clears the managerid tbID.Clear() End If

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      You appear to be doing no validation before injecting the values from the user interface into the SQL. An invalid input could be causing problems. It could also be used by a malicious person in order to damage the database. See SQL Injection Attacks and Tips on How To Prevent Them[^]


      Upcoming events: * Glasgow: Introduction to AJAX (2nd May), SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

      1 Reply Last reply
      0
      • P peteyshrew

        i am trying to read a number from an access table check it and use it to control access to another page. this is the code snippet where i think the problem is and the feedback i'm getting is saying this "Data type mismatch in criteria expression" - referring to the highlighted line of code below. Dim PinNumber As String PinNumber = "SELECT DISTINCT Pin FROM Accounts WHERE Pin='" & Me.tbPin.Text & "'AND AccountID = '" & Me.tbID.Text & "'" comm.CommandText = PinNumber 'the variable is declared as a command dr = comm.ExecuteReader 'gives the variable a value If dr.Read() Then 'if the entry is correct (readable) Form2.Show() 'show the index varibale (form) Me.Close() 'close the current form Else 'if the entry is incorrect MessageBox.Show("Invalid Pin, please try again") 'displays error message tbPin.Clear() 'clears the managerid tbID.Clear() End If

        R Offline
        R Offline
        RichardBerry
        wrote on last edited by
        #3

        peteyshrew wrote:

        & Me.tbPin.Text & "'AND AccountID = '"

        Don't you need a space before the AND. I.e. "' AND AccountID...

        C C 2 Replies Last reply
        0
        • R RichardBerry

          peteyshrew wrote:

          & Me.tbPin.Text & "'AND AccountID = '"

          Don't you need a space before the AND. I.e. "' AND AccountID...

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          What he needs is to parameterise the query.


          Upcoming events: * Glasgow: Introduction to AJAX (2nd May), SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

          1 Reply Last reply
          0
          • R RichardBerry

            peteyshrew wrote:

            & Me.tbPin.Text & "'AND AccountID = '"

            Don't you need a space before the AND. I.e. "' AND AccountID...

            C Offline
            C Offline
            ChandraRam
            wrote on last edited by
            #5

            RichardBerry wrote:

            Don't you need a space before the AND. I.e. "' AND AccountID...

            No... the ' (single quote) acts as a delimiter too, and this will work, provided that PIN is a text type field.

            C 1 Reply Last reply
            0
            • C ChandraRam

              RichardBerry wrote:

              Don't you need a space before the AND. I.e. "' AND AccountID...

              No... the ' (single quote) acts as a delimiter too, and this will work, provided that PIN is a text type field.

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              ChandraRam wrote:

              and this will work, provided that PIN is a text type field.

              And so long as the user doesn't type anything dodgy in to the PIN TextBox because as soon as that happens all hell breaks loose and the company finds that their database is compromised.


              Upcoming events: * Glasgow: Introduction to AJAX (2nd May), SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups