2013-10-18 55 views
1

我試圖從初始SQL查詢中使用resultSet中的記錄作爲循環控制,並將值填充到後續的SQL語句中。後面的SQL語句resultSet將被用來填充一個HTML表格。無效For循環控制變量,嵌套ResultSet SQL

在試圖做到這一點,我打這個問題

微軟VBScript編譯錯誤 '800a0410'

無效 'for' 循環控制變量

/ps/testcli.asp,行83

對於每個objFieldValue在RS.Fields

------------------ -----^

我最初的想法是,它無法辨別客戶RS和RS之間,但似乎並非如此。下面的行從39開始 - 97

SQLDel = "DELETE * FROM ClientModuleList" 
SQLDel2 = "DELETE FROM PSS.dbo.TestCli" 

'------ 
SQLGetClientsV1MVSOld = "SELECT ClientID FROM PSS.dbo.CLIENTS WHERE CardpacVersion='Cardlink 1.0' AND OS='MVS'AND Base='Old'AND Active='1'" 
SQLGetClientsV1MVSNew = "SELECT ClientID FROM CLIENTS WHERE CardpacVersion='Cardlink 1.0' , OS='MVS', Base='New', Active='1'" 
SQLGetClientsV1AS4Old = "SELECT ClientID FROM CLIENTS WHERE CardpacVersion='Cardlink 1.0' , OS='AS4', Base='Old', Active='1'" 
SQLGetClientsV2MVSOld = "SELECT ClientID FROM CLIENTS WHERE CardpacVersion='Cardlink 2.0' , OS='MVS', Base='Old', Active='1'" 
'------ 
SQLGetModules01 = "SELECT Patchlib FROM " 
SQLGetModules02 = " WHERE Type='B' AND Required='1'" 

'-- Connection -- 
Set connDBO = Server.CreateObject("ADODB.Connection") 

'-- ResultSets -- 
Set clientRS = Server.CreateObject("ADODB.RecordSet") 
Set RS = Server.CreateObject("ADODB.RecordSet") 

If Request.Form("submit") <> "" Then 

'--Delete All Existing Rows --S001--  
    connDBO.open cString 
    connDBO.execute(SQLDel2) 
    connDBO.close 
'--Delete All Existing Rows --E001--  

'--Get all Clients which satisfy (Cardlink 1.0, MVS, Old, Active) into clientsRS --S002-- 
    clientRS.Open SQLGetClientsV1MVSOld, cString 

    While NOT clientRS.EOF 
     For Each objFieldValue in clientRS.Fields 
      SQLGetModuleFull = "" & SQLGetModule01 & objFieldValue.Value & SQLGetModule02 & "" 
      RS.Open SQLGetModuleFull, cString 

       Response.Write("<table border='1'>") 
       Response.Write("<tr>") 
       For Each objFieldName in RS.Fields 
        Response.Write("<th>" & objFieldName.Name & "</th>") 
       Next 
       Response.Write("</tr>") 
       If NOT RS.EOF Then 
        While NOT RS.EOF 
         Response.Write("<tr>") 
          For Each objFieldValue in RS.Fields 
           Response.Write("<td>" & objFieldValue.Value & "</td>") 
          Next 
         Response.Write("</tr>") 
         RS.MoveNext 
        WEnd   
        Response.Write("</table>") 
       End If 
     Next 
    WEnd 

    RS.Close 
    clientRS.Close 

End If 

任何提示爲什麼發生這種情況? 我很新的ASP腳本中使用VBScript

回答

4

「當你嵌套循環,每個循環必須有一個獨特的元素變量。」 http://msdn.microsoft.com/en-us/library/vstudio/5ebk1751.aspx

你不能在嵌套循環For Each重複使用相同的元素名稱兩次:

For Each objFieldValue in clientRS.Fields 
[...] 
    For Each objFieldValue in RS.Fields 

更改第二到objFieldValue2(或更好的名字),看看它是否編譯。

+0

謝謝。這解決了編譯問題。 – HexEDSyght