案例分析:在我进行分页的时候用到如下SQL语句,
SELECT F_ID,F_Card,F_AvaBegin,F_AvaEnd,F_EditTime from
(select top @End * from
(select top @Start * FROM T_Trade_Card_Usefullife
where F_Card=@F_Card
order by F_EditTime desc)DERIVETBL
order by F_EditTime)A
order by F_EditTime desc
运行显示如下错误:(select top @End * from
(select top @Start * FROM T_Trade_Card_Usefullife
where F_Card=@F_Card
order by F_EditTime desc)DERIVETBL
order by F_EditTime)A
order by F_EditTime desc
Incorrect syntax near '@End'.
Incorrect syntax near '@Start'.
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.SqlClient.SqlException: Incorrect syntax near '@End'.
Incorrect syntax near '@Start'.
看来SQL语句有问题,我就一直在寻找,这些参数是有SqlParameter集合提供,如果我直接用数值代替这些参数,则程序能够正确运行,看来的确出自End和start的错误,经过不断的调试,和大胆的推测,最后在参数加入了括号,问题解决啦。SQL语句如下:Incorrect syntax near '@Start'.
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.SqlClient.SqlException: Incorrect syntax near '@End'.
Incorrect syntax near '@Start'.
SELECT F_ID,F_Card,F_AvaBegin,F_AvaEnd,F_EditTime from
(select top (@End) * from
(select top (@Start) * FROM T_Trade_Card_Usefullife
where F_Card=@F_Card
order by F_EditTime desc)DERIVETBL
order by F_EditTime)A
order by F_EditTime desc
(select top (@End) * from
(select top (@Start) * FROM T_Trade_Card_Usefullife
where F_Card=@F_Card
order by F_EditTime desc)DERIVETBL
order by F_EditTime)A
order by F_EditTime desc