ASP NET SqlException: 语法不正确

ASP NET SqlException: Incorrect Syntax

我的 ASP NET 网页中有一个方法可以执行 SQL 命令。当我执行以下命令时,我得到

SqlException was unhandled by user code

SQL 错误是

Incorrect syntax near Chemicals'

这里是 SQL 命令字符串:

SELECT MainHeading 
FROM Areas 
INNERJOIN Chemicals ON Areas.AreaNo = Chemicals.AreaNo 
WHERE (Chemicals.IDMark = @item)

其中 @item 是会话变量。

简化后的表格如下

您在 innerjoin

之间错过了一个 space
SELECT MainHeading 
FROM Areas 
INNER JOIN Chemicals ON Areas.AreaNo = Chemicals.AreaNo 
WHERE (Chemicals.IDMark = @item)

必须是:

SELECT MainHeading FROM Areas INNER JOIN Chemicals ON Areas.AreaNo = Chemicals.AreaNo WHERE (Chemicals.IDMark = @item)

INNER JOIN是两个字:)

作为给您的信息,INNER JOINJOIN 相同。