日期:2014-05-19  浏览次数:20943 次

关键字 'where' 附近有语法错误
string   sql   =   string.Format( "Select   *   from   (   SELECT   dbo.account.id,   dbo.account.name,   dbo.account.description,   dbo.[group].name   AS   GroupName,   dbo.lot_limit.name   AS   LotLimitName, "   +
                        "dbo.money_limit.name   AS   MoneyLimitName   FROM   dbo.account   INNER   JOIN   dbo.[group]   ON   dbo.account.group_id   =   dbo.[group].id   INNER   JOIN   "   +
                        "dbo.lot_limit   ON   dbo.[group].id   =   dbo.lot_limit.group_id   INNER   JOIN   dbo.group_money_limit   ON   dbo.[group].id   =   dbo.group_money_limit.group_id   INNER   JOIN   "   +
                        "dbo.money_limit   ON   dbo.group_money_limit.money_limit_id   =   dbo.money_limit.id   )   where   (dbo.account.name   like   '{0} '   or   dbo.account.description   like   '{1} ')   order   by   dbo.account.id ",
                        this.TextBox1.Text,   this.TextBox1.Text   );

运行出错说是:
关键字   'where '   附近有语法错误。  
Description:   An   unhandled   exception   occurred   during   the   execution   of   the   current   web   request.   Please   review   the   stack   trace   for   more   information   about   the   error   and   where   it   originated   in   the   code.  




------解决方案--------------------
如果你真的喜欢拼字符串的话, 在执行SQL命令时TRY一下,并在CATCH里输出你的SQL命令
------解决方案--------------------
先在查询分析器里执行下
------解决方案--------------------
先把SQL语句输出来看下!

放到查询分析器里面运行下就知道!
------解决方案--------------------
把中間的改為視圖
------解决方案--------------------
直接这样写不行吗?
为什么要加一个子查询
SELECT dbo.account.id, dbo.account.name, dbo.account.description, dbo.[group].name AS GroupName, dbo.lot_limit.name AS LotLimitName,dbo.money_limit.name AS MoneyLimitName FROM dbo.account INNER JOIN dbo.[group] ON dbo.account.group_id = dbo.[group].id INNER JOIN dbo.lot_limit ON dbo.[group].id = dbo.lot_limit.group_id INNER JOIN dbo.group_money_limit ON dbo.[group].id = dbo.group_money_limit.group_id INNER JOIN dbo.money_limit ON dbo.group_money_limit.money_limit_id = dbo.money_limit.id where dbo.account.name like '{0} ' or dbo.account.description like '{1} ') order by dbo.account.id