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

SQL:like语句附近有错误
public   DataSet   GetSQLdataByApplyId(string   strUserId,   string   strApplyNO)
        {
                string   strSQL2   =   "SELECT   CONVERT(nvarchar,   OverTimeHead.CreateDateTime,   111)   AS   CreateDateTime_short,   OverTimeHead.OverTimeHeadId,   OverTimeHead.UserId,   aspnet_Users.UserName,   OverTimeStatus.StatusName,   OverTimeHead.ApplyNo,   OverTimeHead.OrgName,   OverTimeHead.OverTimeStatusId   FROM   OverTimeHead   LEFT   OUTER   JOIN   OverTimeStatus   ON   OverTimeHead.OverTimeStatusId   =   OverTimeStatus.OverTimeStatusId   LEFT   OUTER   JOIN   aspnet_Users   ON   OverTimeHead.UserId   =   aspnet_Users.UserId "   +
                "WHERE   (OverTimeHead.ApplyNo   LIKE   '%{1}% ')   AND   (OverTimeHead.UserId   =   ' "   +   strUserId   +   " ')   ";//显示和自己部门相关的便可

                strSQL2   =   string.Format(strSQL2,   strUserId.ToString(),   strApplyNO);

                return   new   CommonData().ExeQuery(strSQL2);
        }


------解决方案--------------------
OverTimeHead.UserId = aspnet_Users.UserId " +
"WHERE (OverTimeHead.ApplyNo LIKE '%{1}% ') AND (OverTimeHead.UserId = ' " + strUserId + " ') ";

这个字符串会被连接成....aspnet_Users.UserIdWHERE (OverTimeHead.ApplyNo LIKE '%{1}% ')...
UserId 和 WHERE 之间要有空格。