查询表达式中的语法错误(逗号),带逗号的标题

时间:2014-04-08 11:28:47

标签: vb.net select syntax-error dbf

我正在尝试检查来自label1的值是否存在于名为“NALOG,C,8”的dbf文件列中。 DBF文件中的标题我无法更改,因为它表示列的格式和字段大小。但是我得到了这个错误:“查询表达式中的语法错误(逗号)”NALOG,C,8 = @NAL“

这是完整的代码:

Dim con As New OleDbConnection
    Dim cmd As New OleDbCommand

    Dim FilePath As String = "C:\"
    Dim DBF_File As String = "PROMGL"
    Dim ColName As String = "NALOG,C,8"
    'Dim SQLstr As String = "SELECT * FROM " & DBF_File
    con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FilePath & _
    " ;Extended Properties=dBASE IV;User ID=Admin;Password="
    'cmd = New OleDbCommand("SELECT * FROM " & DBF_File)
    cmd = New OleDbCommand("SELECT * FROM PROMGL WHERE " & ColName & " = @NAL")


    cmd.Connection = con
    con.Open()
    cmd.Parameters.AddWithValue("@NAL", Label1.Text)
    Using reader As OleDbDataReader = cmd.ExecuteReader()
        If reader.HasRows Then
            con.Close()
            Label6.Text = "EXIST" & TextBox1.Text
            TextBox1.Text = ""
            TextBox1.Focus()

        Else
            Label6.Text = "DOESN'T EXIST"

        End If
    end using

感谢。

2 个答案:

答案 0 :(得分:2)

如果您有一个名为this的列:

Dim ColName As String = "NALOG,C,8"

然后我也会改变它:

Dim ColName As String = "[NALOG,C,8]"

答案 1 :(得分:0)

请改用:

Dim ColName As String = "NALOG"