vb.net vb/access 上的查询表达式中的语法错误(缺少运算符)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13677443/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 11:25:52  来源:igfitidea点击:

Syntax error (missing operator) in query expression on vb/access

vb.netoperator-keyword

提问by Billy Otsuka

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='.

这是我的问题: 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()

突出显示的词是 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.

在此代码中,我想输入一个 4 号密码,如果正确,我可以转到下一个表格,但如果错误,则不会。我正在使用访问数据库。

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

如果有人能告诉我出了什么问题,我真的很感激,因为我不知道错误是什么。

回答by Carlos Landeras

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)

回答by Hasan

What is textbox1.text type?

什么是 textbox1.text 类型?

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

回答by hatsrumandcode

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"