0
我真的不明白爲什麼if測試總是失敗。我已驗證會話變量sCrs_cde(課程代碼)是否正確,並且只存在於sql查詢返回的多個記錄中的一箇中。 (這是與年份和學期相關的外鍵的一部分)。我正在嘗試爲課程名稱設置價值,但它總是寫出一個空值('')ASP Classic - 如果測試失敗
Dim Recordset1
Dim Recordset1_cmd
Dim Recordset1_numRows
Set Recordset1_cmd = Server.CreateObject ("ADODB.Command")
Recordset1_cmd.ActiveConnection = MM_Jenz_STRING
Recordset1_cmd.CommandText = "SELECT ID_NUM, Crs_Title, YR_CDE, TRM_CDE, CRS_CDE, TRANSACTION_STS, SUBTERM_CDE FROM dbo.STUDENT_CRS_HIST WHERE ID_NUM = ? And Transaction_sts = 'C' "
Recordset1_cmd.Prepared = true
Recordset1_cmd.Parameters.Append Recordset1_cmd.CreateParameter("param1", 5, 1, -1, Recordset1__MMColParam) ' adDouble
Set Recordset1 = Recordset1_cmd.Execute
Recordset1_numRows = 0
%>
<%
Do While not Recordset1.Eof
response.write(Recordset1.Fields.Item("CRS_cde").Value)
IF (Recordset1.Fields.Item("CRS_cde").Value) = (Session("sCrs_cde")) THEN
Session("sCrs_Title") = (Recordset1.Fields.Item("CRS_Title").Value)
Session("sYr_cde") = (Recordset1.Fields.Item("YR_CDE").Value)
Session("sTrm_cde") = (Recordset1.Fields.Item("Trm_Cde").Value)
Session("sSubterm_cde") = (Recordset1.Fields.Item("Subterm_cde").Value)
EXIT Do
ELSE
Recordset1.movenext
END IF
Loop
什麼數據類型是CRS_cde?我將會話(「sCRS_cde」)保存到一個變量,確保它是相同的數據類型(整數),然後比較。如果您將整數與字符串進行比較,則可以解釋您的問題 – Sparky
爲什麼在while循環之前有服務器標記('%><%') – meda
@meda - 可能是剪切,複製和粘貼的結果。他正在關閉一個腳本塊並在下面一行打開另一個,這是不必要的,但實際上並不是錯誤的 – John