简体   繁体   中英

Incorrect syntax near 'tblAPInvSub' in VB.net & SQL Server 2008

I have this query:

Public Sub LoadList(ByVal InvNo As String)
        Dim params As ListDictionary = New ListDictionary
        Dim query As String


        params.Add(_tblAPInvSub.ColumnNames.InvNo, InvNo)

        query = "SELECT tblAPInvSub.InvNo, tblAPInvSub.GLCode,
tblGLAccounts.GLName, tblAPInvSub.SLCode,tblSLAccounts.SLName,
ISNULL(tblAPInvSub.DRAmt,0) AS DRAmt, ISNULL(tblAPInvSub.CRAmt,0) AS
CRAmt, tblAPInvSub.LineID " & _
                "FROM tblAPInvSub INNER JOIN  tblGLAccounts ON
tblAPInvSub.GLCode = tblGLAccounts.GLCode " & _
                "INNER JOIN tblSLAccounts ON tblAPInvSub.SLCode =
tblSLAccounts.SLCode" & _
                "WHERE tblAPInvSub.InvNo = @InvNo "


        LoadFromSql(query, params, CommandType.Text)
    End Sub

Of I omit the where clause it will work, else it will return the error:

Incorrect syntax near 'tblAPInvSub'

Any idea why this is happening?

tblSLAccounts.SLCode之后或WHERE之前放置一个空格

try like this

   select * from 
    (
    <your long query what you posted>
    )x
    WHERE tblAPInvSub.InvNo = @InvNo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM