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. Help with OLEDB error [modified]

Help with OLEDB error [modified]

Scheduled Pinned Locked Moved Visual Basic
databasesecurityhelpquestion
6 Posts 3 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.
  • B Offline
    B Offline
    Brad
    wrote on last edited by
    #1

    Hi, I am coding a login which involoves database verification. For extra security I added a new column to my database and added the extra code accordingly and I am getting this exception.. System.Data.OleDb.OleDbException was unhandled ErrorCode=-2147217900 Message="Syntax error (missing operator) in query expression 'USERID='Brad' PASSID='test'' AND HardwareID='BRAD-8EYRYEUOH4'." Source="Microsoft JET Database Engine" Here is the source for my project: Imports System.Data Imports System.Data.OleDb Public Class Form1 Dim mypath = "C:\Temp\mydb.mdb" Dim mypassword = "" Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mypath & ";Jet OLEDB:Database Password=abc123" & mypassword) Dim cmd As OleDbCommand Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim sql = "SELECT UserID ,PassID, HardwareID FROM MYTAB WHERE USERID='" & TextBox1.Text & "' PASSID='" & TextBox2.Text & "' AND HardwareID='" & TextBox3.Text cmd = New OleDbCommand(sql, conn) conn.Open() Dim dr As OleDbDataReader = cmd.ExecuteReader Try If dr.Read = False Then MessageBox.Show("Authentication failed...") Else MessageBox.Show("Login successfully...") End If Catch ex As Exception MsgBox(ex.Message) End Try conn.Close() End SubI am completly stumped and dont understand what I have done wrong? Teh code was working fine until I added this extra bit in: HardwareID='" & TextBox3.Text Many Thanks -- modified at 20:44 Thursday 18th October, 2007

    N 1 Reply Last reply
    0
    • B Brad

      Hi, I am coding a login which involoves database verification. For extra security I added a new column to my database and added the extra code accordingly and I am getting this exception.. System.Data.OleDb.OleDbException was unhandled ErrorCode=-2147217900 Message="Syntax error (missing operator) in query expression 'USERID='Brad' PASSID='test'' AND HardwareID='BRAD-8EYRYEUOH4'." Source="Microsoft JET Database Engine" Here is the source for my project: Imports System.Data Imports System.Data.OleDb Public Class Form1 Dim mypath = "C:\Temp\mydb.mdb" Dim mypassword = "" Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mypath & ";Jet OLEDB:Database Password=abc123" & mypassword) Dim cmd As OleDbCommand Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim sql = "SELECT UserID ,PassID, HardwareID FROM MYTAB WHERE USERID='" & TextBox1.Text & "' PASSID='" & TextBox2.Text & "' AND HardwareID='" & TextBox3.Text cmd = New OleDbCommand(sql, conn) conn.Open() Dim dr As OleDbDataReader = cmd.ExecuteReader Try If dr.Read = False Then MessageBox.Show("Authentication failed...") Else MessageBox.Show("Login successfully...") End If Catch ex As Exception MsgBox(ex.Message) End Try conn.Close() End SubI am completly stumped and dont understand what I have done wrong? Teh code was working fine until I added this extra bit in: HardwareID='" & TextBox3.Text Many Thanks -- modified at 20:44 Thursday 18th October, 2007

      N Offline
      N Offline
      nlarson11
      wrote on last edited by
      #2

      your missing the AND WHERE USERID='" & TextBox1.Text & "' AND PASSID='"

      B 1 Reply Last reply
      0
      • N nlarson11

        your missing the AND WHERE USERID='" & TextBox1.Text & "' AND PASSID='"

        B Offline
        B Offline
        Brad
        wrote on last edited by
        #3

        Hi, I added the extra AND and here is the error what I am getting now! Syntax error in string in query expression 'USERID='Brad' AND PASSID='test' AND HARDWAREID='BRAD-8EYRYEUOH4'. The exception is on this line of code in my source:

        Dim dr As OleDbDataReader = cmd.ExecuteReader

        Thanks

        T 1 Reply Last reply
        0
        • B Brad

          Hi, I added the extra AND and here is the error what I am getting now! Syntax error in string in query expression 'USERID='Brad' AND PASSID='test' AND HARDWAREID='BRAD-8EYRYEUOH4'. The exception is on this line of code in my source:

          Dim dr As OleDbDataReader = cmd.ExecuteReader

          Thanks

          T Offline
          T Offline
          Tom Deketelaere
          wrote on last edited by
          #4

          Dim sql = "SELECT UserID ,PassID, HardwareID FROM MYTAB WHERE USERID='" & TextBox1.Text & "' PASSID='" & TextBox2.Text & "' AND HardwareID='" & TextBox3.Text like said above you are missing the AND but also a "'" at the end of you sql string so the above string becomes: Dim sql = "SELECT UserID ,PassID, HardwareID FROM MYTAB WHERE USERID='" & TextBox1.Text & "' AND PASSID='" & TextBox2.Text & "' AND HardwareID='" & TextBox3.Text & "'" hope this helps

          If my help was helpfull let me know, if not let me know why. The only way we learn is by making mistakes.

          B 1 Reply Last reply
          0
          • T Tom Deketelaere

            Dim sql = "SELECT UserID ,PassID, HardwareID FROM MYTAB WHERE USERID='" & TextBox1.Text & "' PASSID='" & TextBox2.Text & "' AND HardwareID='" & TextBox3.Text like said above you are missing the AND but also a "'" at the end of you sql string so the above string becomes: Dim sql = "SELECT UserID ,PassID, HardwareID FROM MYTAB WHERE USERID='" & TextBox1.Text & "' AND PASSID='" & TextBox2.Text & "' AND HardwareID='" & TextBox3.Text & "'" hope this helps

            If my help was helpfull let me know, if not let me know why. The only way we learn is by making mistakes.

            B Offline
            B Offline
            Brad
            wrote on last edited by
            #5

            Thank you so much!!! I cant believe it was something that simple!!! Cheers again!

            T 1 Reply Last reply
            0
            • B Brad

              Thank you so much!!! I cant believe it was something that simple!!! Cheers again!

              T Offline
              T Offline
              Tom Deketelaere
              wrote on last edited by
              #6

              no problem I learned the hard way to check my sql string char by char (searched for the same thing a long long time a while back so...)

              If my help was helpfull let me know, if not let me know why. The only way we learn is by making mistakes.

              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