<%
'记录集转二维数组方法
ErrMsg=""
Function RecordSetToArray(rs)
Dim r,c,reAry()
ReDim reAry(rs.recordcount,rs.Fields.count)
IF rs.EOF Then
ErrMsg="数据库记录为空"
Else
r=0
Do Until rs.EOF
For c=0 To rs.Fields.count-1
reAry(r,c)=CStr(rs.Fields(c).Value)
Next
r=r+1
rs.movenext
Loop
End IF
RecordSetToArray=reAry
End Function
'调用示例
'省略数据库打开代码,数据库连接对象为con
Dim rs,r,c,rsAry()
Set rs=Server.CreateObject("ADODB.RecordSet")
rs.Open "select * from [tablename]" ,con,1,1
'tablename换成要显示的表名
rsAry=RecordSetToArray(rs)
IF ErrMsg<>"" Then
Response.Write ErrMsg
Else
With Response
.Write "<table>"
For r=0 To rs.recordcount
.Write "<tr>"
For c=0 To rs.Fields.count-1
.Write "<td>"&rsAry(r,c)&"</td>"
Next
.Write "</tr>"
Next
.Write "</table>"
End With
End IF
%>
以上代码没有测试不知道能不能运行。
[[italic] 本帖最后由 yms123 于 2007-12-7 16:32 编辑 [/italic]]