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