为什么我收到错误“查询表达式中的语法错误”

时间:2015-09-16 10:22:53

标签: ms-access-2010 vb.net-2010

我得到错误我喜欢这个“QUERY EXPRESSION中的语法错误_Name =''” 请帮帮我 。我的代码出了什么问题?

尝试

        Connection.Open()
        Dim query As String
        query = ("SELECT * from RegistrationTable WHERE _Name = '" & ListBox1.Text & "'")

        command = New OleDbCommand(query, Connection)
        Reader = command.ExecuteScalar
        While Reader.Read
            txtPID.Text = Reader("PatientID")
            txtName.Text = Reader("_Name")
            txtAge.Text = Reader("_Age")
            cmbGender.Text = Reader("_Gender")

        End While
        Connection.Close()
    Catch ex As Exception
        MsgBox(ex.Message)

    Finally
        Connection.Dispose()
    End Try

1 个答案:

答案 0 :(得分:0)

该下划线表示您需要方括号:

"SELECT * from RegistrationTable WHERE [_Name] = '" & ListBox1.Text & "'"