在ASP经典中拆分数组和显示表?如何?

时间:2015-03-29 16:19:26

标签: vbscript asp-classic split

桌房

ID:1 | OFName: Room1

ID:2 | OFName: Room2

ID:3 | OFName: Room3

表格文件

ID:12 | Code:123/PA | RoomID: 1,2,3

ID:13 | Code:12/HC  | RoomID: 2

ID:14 | Code:121/CA | RoomID: 2,3

ID:15 | Code:141/PC | RoomID: 1,3

我希望这样显示

ROOM1

ID | Code

12 | 123/PA

15 | 141/PC

室2

ID | Code

12 | 123/PA

13 | 12/HC

15 | 141/PC

我这样写但错了!

<%
SQLDV = " Select ID,OFName From Room" 
CREATECONNECTION()
rs.open SQLDV,ObjConn,1 ,3 
While not rs.eof
response.write("" & rs(" OFName ") & "")
%>
<%
        Create2ndRs()
            SQLSearch = "SELECT ID,Code From Document"
            ListArray = split(RoomID, ",")
                For i = 0 to UBound(ListArray)-1
                    sqlWhere =sqlWhere & " (ListArray(i)=" & rs("ID") & ") "
                Next
                SQLSearch = SQLSearch & "where" & sqlWhere
                rs1.open SQLSearch,ObjConn,1 ,3 
                While not rs1.eof 
                    response.write("" & rs1("ID") & "","" & rs1("Code") & "")
                rs1.movenext
                wend
        rs1.close
rs.movenext
wend
CLOSECONNECTION()%>

1 个答案:

答案 0 :(得分:0)

你有四行代码不能正常工作,每一行都会给你自己的错误。你不能这样做:

response.write(" & "rs(" OFName ") & "")

这应该是这样的(即使你不认为你需要它也总是使用修剪,这只是一个很好的做法......):

response.write trim(rs("OFName"))

你的方式'ListArray(i)'在字符串中。你不能这样做:

sqlWhere = sqlWhere & " (ListArray(i)=" & rs("ID") & ") '"

这应该是这样的:

sqlWhere = sqlWhere & "(" & trim(ListArray(i)) & "=" & trim(rs("ID")) & ")"

在我们的表名之后和之前没有空格,所以这个:

SQLSearch = SQLSearch & "where" & sqlWhere

应该是

SQLSearch = SQLSearch & " where " & sqlWhere 

你也不能这样做:

response.write("" & rs1("ID") & "","" & rs1("Code") & "")

我想你需要:

response.write trim(rs1("ID")) & "," & trim(rs1("Code"))