查询表达式vb.net中缺少运算符

时间:2011-12-09 19:18:34

标签: sql vb.net ms-access ado.net oledb

我从下面的查询中收到以下错误:

查询表达式'LTC_FBS.DBS_NM = LTC_FBS_EMP.EMP_ID中的语法错误(缺少运算符) 在LTC_FBS.FBS_REV = LTC_FBS_REV.REV_I'上INNER JOIN LTC_FBS_REV。

     Dim sSQL As String = "SELECT FBS_ID, CLM_NUM, EMP_NM, REV_NM, DATE_SUBMIT FROM 
    LTC_FBS f INNER JOIN LTC_FBS_EMP e on f.DBS_NM = e.EMP_ID INNER JOIN LTC_FBS_REV r on 
   f.FBS_REV = r.REV_ID WHERE "

    If OptClaimNo.Checked = True Then 
        sSQL &= "CLM_NUM Like ('" & txtClaimNo.Text & "%')"

这是所有代码:

        Private sConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=O:\UA\FINANCE\LTC\MIS\Department\Databases\FBS.accdb"
Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearch.Click
    Me.lstResults.DataSource = Nothing
    Me.lstResults.Refresh()






    Dim OptControlArray() As Control = {OptClaimNo, OptDate, OptCustodian}


    Dim sSQL As String = "SELECT FBS_ID, CLM_NUM, EMP_NM, REV_NM, DATE_SUBMIT FROM LTC_FBS INNER JOIN LTC_FBS_EMP on LTC_FBS.DBS_NM = LTC_FBS_EMP.EMP_ID INNER JOIN LTC_FBS_REV on LTC_FBS.FBS_REV = LTC_FBS_REV.REV_ID WHERE "
    sSQL &= "CLM_NUM Like ('" & txtClaimNo.Text & "%')"
    ' If OptClaimNo.Checked = True Then
    'sSQL &= "CLM_NUM Like ('" & txtClaimNo.Text & "%')"

    'sSQL &= "Last Like ('" & txtLastName.Text & "%') AND First Like ('" & txtFirstName.Text & "%')"
    ' ElseIf OptCustodian.Checked = True Then
    ' sSQL &= "DBS_NM Like ('" & cboCustodian.SelectedValue & "%')"
    'ElseIf OptDate.Checked = True Then
    ' sSQL &= "DATE_SUBMIT = ('" & txtDateRec.Text & "')"
    ' End If

    Dim conn As New System.Data.OleDb.OleDbConnection(sConnectionString)
    conn.Open()

    Dim dat As OleDbDataAdapter = New OleDbDataAdapter(sSQL, conn)
    Dim dt As New DataTable()

    dat.Fill(dt)
    dat.Dispose()

    If dt.Rows.Count <> 0 Then
        lstResults.DataSource = dt
        Me.lstResults.Columns("FBS_ID").Visible = False
        Me.lstResults.Columns("REV_NM").Width = 125
        Me.lstResults.Columns("EMP_NM").Width = 100
        Me.lstResults.Columns("DATE_SUBMIT").Width = 150

    Else
        MsgBox("No records were found.")
    End If

    dt.Dispose()
    conn.Close()

   End Sub
   End Class

1 个答案:

答案 0 :(得分:3)

问题是两个内连接。您需要用parens包围第一个,以便访问权限正确处理。

变化:

Dim sSQL As String = "SELECT FBS_ID, CLM_NUM, EMP_NM, REV_NM, DATE_SUBMIT FROM LTC_FBS INNER JOIN LTC_FBS_EMP on LTC_FBS.DBS_NM = LTC_FBS_EMP.EMP_ID INNER JOIN LTC_FBS_REV on LTC_FBS.FBS_REV = LTC_FBS_REV.REV_ID WHERE "

为:

Dim sSQL As String = "SELECT FBS_ID, CLM_NUM, EMP_NM, REV_NM, DATE_SUBMIT FROM (LTC_FBS INNER JOIN LTC_FBS_EMP on LTC_FBS.DBS_NM = LTC_FBS_EMP.EMP_ID) INNER JOIN LTC_FBS_REV on LTC_FBS.FBS_REV = LTC_FBS_REV.REV_ID WHERE "