0

I've been looking for an answer but I can't understand them since I'm noob on visual basic (I haven't been taught how to use it in school, I just search on the net to learn).

Here is my problem: Syntax error (missing operator) in query expression 'pinN='.

Dim con As New OleDbConnection("PROVIDER = Microsoft.ACE.OLEDB.12.0;Data Source =   C:\Users\Billy Otsuka\Desktop\VB Fiiles\Prototype-Prototype\Sample.accdb")
Dim cmd As OleDb.OleDbCommand = New OleDbCommand("SELECT * FROM [Table3] WHERE pinN= " & TextBox1.Text & "", con)
con.Open()
Dim sdr As OleDbDataReader = cmd.ExecuteReader()
If (sdr.Read() = True) Then
    adminLogin.Show()
    Me.Hide()
Else
    MsgBox("Invalid pin")
End If

The highlighted word is sdr As OleDbDataReader = cmd.ExecuteReader()

In this code I want to enter a 4 number pin and if its correct I can go to the next form but if its wrong it will not. I'm using an access database.

I really appreciate if anyone can tell me what's wrong since i don't have any idea what the error is.

3 Answers 3

1

Use this:

 Dim cmd As OleDb.OleDbCommand = New OleDbCommand("SELECT * FROM
 [Table3] WHERE pinN= '"  & TextBox1.Text & "'", con)

You don't have the singles quotes on your select

EDIT: Try this:

 New OleDbCommand("SELECT * FROM [Table3] WHERE pinN= " & TextBox1.Text, con)
Sign up to request clarification or add additional context in comments.

7 Comments

after putting single quotes i got now the error Data type mismatch in criteria expression.
what is the value in Textbo2.text is it a date or plain text?. What value is in it debugging?
value i put is 1234 since its asking for a pin.
Trry with this: New OleDbCommand("SELECT * FROM [Table3] WHERE pinN= " & TextBox1.Text, con)
can i ask one more. It works if i put numbers but if i leave it blank it gives me the missing operator error. do you know how to fix it?
|
0

What is textbox1.text type?

If textbox1.text is **numeric** :
   New OleDbCommand("SELECT * FROM [Table3] WHERE pinN= " & TextBox1 & ""
else
   New OleDbCommand("SELECT * FROM [Table3] WHERE pinN ='" & TextBox1 & "'"

Comments

0

I had issue doing the concatenation, I used a parameter to solve this issue.

Dim cmd As OleDb.OleDbCommand = New OleDbCommand("SELECT * FROM [Table3] WHERE pinN= @myPinN", con)
con.Open()  
cmd.Parameters.Add("@myPinN", OleDbType.VarChar, 100).Value = "myPinNValue"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.