0
我有這樣的查詢拋出....分配錯誤在查詢
selectLeaveDetails =
"SELECT UL.[PK_ID],UD.FIRST_NAME + ' ' + UD.LAST_NAME AS REQUESTBY," +
"UL.[DATE_FROM] AS FROMDATE,UL.[DATE_TO] AS TODATE," +
"UL.LEAVE_REQUEST_ON AS REQUESTON," +
"REPLACE(UL.LEAVE_REQUEST_NOTES, '\n', '<br />') AS REQUESTNOTES," +
"STATUS=CASE " +
" WHEN UL.[LEAVE_STATUS] = '1' THEN 'ACTIVE' " +
" WHEN UL.[LEAVE_STATUS] = '-1' THEN 'CANCELLED' " +
" WHEN UL.[LEAVE_STATUS] = '2' THEN 'REPLACED' END," +
"UL.LEAVE_RESPONSE_ON AS RESPONSEON," +
"ULL.FIRST_NAME + ' ' + ULL.LAST_NAME AS RESPONSEBY," +
"UL.[LEAVE_RESPONSE_NOTES] AS RESPONSENOTES,UL.FK_LEAVE_REQUESTER " +
"FROM (M_USER_LEAVES UL " +
"INNER JOIN M_LEADERLED MLL ON MLL.LED_ID = MUD.PK_ID WHERE MLL.LEADER_ID = '" + Session["UserID"].ToString() ****" +****
"LEFT JOIN M_USER_DETAILS UD ON UD.PK_ID = UL.FK_LEAVE_REQUESTER) " +
"LEFT JOIN M_USER_DETAILS ULL ON ULL.PK_ID = UL.FK_LEAVE_RESPONSE_BY " +
" WHERE UL.DATE_FROM BETWEEN '01/01/" + cmbYearList.SelectedItem.Text + "' AND '12/31/" + cmbYearList.SelectedItem.Text + "'" +
" AND UD.ACTIVE=1";
在cmbYearList.SelectedItem.Text + "' AND '12/31/" + cmbYearList.SelectedItem.Text + "'"
查詢......只有賦值,遞增,遞減引發錯誤
誰能幫助我?
幾點要點:既然你把你的查詢連接在一起,你就打開了自己的SQL注入 - 不要這樣做!改用參數化查詢。另外:對於日期格式,使用「01/01/...」和「12/31/...」會使您的代碼依賴於SQL Server上的語言設置 - 使用ISO-8601格式替代「YYYYMMDD」 - 那些**無論您的語言/地區設置如何,**總是** – 2010-11-27 09:57:43