任何人都可以告诉我在以下查询中写了什么错误,以便显示此错误消息。
strSelectQuery = "SELECT LED_ID AS PK_ID, FIRST_NAME + ' ' + LAST_NAME AS NAME"
+ " FROM M_LEADERLED INNER JOIN M_USER_DETAILS"
+ " ON M_LEADERLED.LED_ID = M_USER_DETAILS.PK_ID"
+ " WHERE (M_LEADERLED.LEADER_ID = " + Session["UserID"].ToString() + ""
+ " AND M_USER_DETAILS.ACTIVE = 1 AND M_LEADERLED.START_DATE <= Getdate()"
+ " AND M_LEADERLED.END_DATE > Getdate())"
+ " UNION SELECT PK_ID, FIRST_NAME + ' ' + LAST_NAME AS NAME"
+ " FROM M_USER_DETAILS WHERE PK_ID = " + Session["UserID"].ToString() + ";";
答案 0 :(得分:2)
您需要围绕Session["UserID"].ToString()
输出的单引号,如下所示:
+ " WHERE (M_LEADERLED.LEADER_ID = '" + Session["UserID"].ToString() + "'"
我是否还应该提到你应该:
Session["UserID"]
之前对ToString()
进行空检查? 编辑:基于OP提供的更新信息,因为密钥是数字的,您不必单引号。你确实需要检查Session["UserID"]
的输出(因为它可能是垃圾或空),你需要向我们展示完全构造的SQL字符串。