合并两个rs结果输出
<%
Const SqlDatabaseName = "DNN625" ' 数据库名字'
Const SqlPassword = "123456" ' 数据库密码'
Const SqlUsername = "sa" ' 数据库帐户'
Const SqlLocalName = "127.0.0.1" ' 数据库地址'
'数据库连接函数'
Sub openConn(ByRef conn)
Dim ConnStr
ConnStr = "Provider = Sqloledb; User ID = " & SqlUsername & "; Password = " & SqlPassword & "; Initial Catalog = " & SqlDatabaseName & "; Data Source = " & SqlLocalName & ";"
On Error Resume Next
'Set conn = Server.CreateObject("ADODB.Connection")
conn.open ConnStr
If Err Then
err.Clear
Set Conn = Nothing
Response.Write "数据库连接出错,请检查连接字串!"
Response.End
End If
End Sub
'默认打开数据库连接
Set conn = Server.CreateObject("ADODB.Connection")
call openConn(conn)
'---------------------------------------------------------------------------
dim rs,strSql ,rs2
set rs = Server.CreateObject("ADODB.RecordSet")
strSql="select ModuleID,ModuleDefID from DNN_Modules(nolock) where moduleid>344 order by ModuleID"
rs.ActiveConnection=conn
rs.Source=strSql
rs.Open()
'do while not rs.EOF
' response.Write (rs("ModuleID") &"("& rs("ModuleDefID") &")"& "</br>")
' rs.MoveNext
'loop
'---------------------------------------------------------------------------
set rs2 = Server.CreateObject("ADODB.RecordSet")
strSql="select ModuleID,SettingName from DNN_ModuleSettings(nolock) order by ModuleID"
rs2.ActiveConnection=conn
rs2.Source=strSql
rs2.Open()
'do while not rs.EOF
' response.Write (rs2("ModuleID") &"("& rs2("SettingName") &")"& "</br>")
' rs2.MoveNext
'loop
dim Array1,Array2,i,j,RowNum1,RowNum2,ColumnNum1,ColumnNum2,str
'使用 GetRows 方法可将记录从 Recordset 复制到二维数组中。第一个下标标识字段,第二个则标识记录号
Array1=rs.GetRows
RowNum1=ubound(Array1,2)
ColumnNum1=ubound(Array1,1)
'for i=0 to ubound(Array1,2)
' response.Write (Array1(0,i) &"("& Array1(1,i) &")"& "</br>")
'next
Array2=rs2.GetRows
RowNum2=ubound(Array2,2)
ColumnNum2=ubound(Array2,1)
'for i=0 to ubound(Array2,2)
' response.Write (Array2(0,i) &"("& Array2(1,i) &")"& "</br>")
'next
dim tmpArr
for i=0 to RowNum1 '行
str= ""
for j=0 to ColumnNum1
str= str& Array1(j,i) &","
next
tmpArr=getDesc(Array1(0,i),Array2)
if IsArray(tmpArr) then
str = str & tmpArr(1)
response.Write (str& "</br>") 'join
end if
response.Write (str& "</br>") 'left join
next
rs.close()
set rs = nothing
rs2.close()
set rs2 = nothing
conn.close()
set conn = nothing
if err.number>0 then
response.write err.description
end if
function getDesc(ByVal id,ByVal Array )
dim i
for i=0 to Ubound(Array,2)
if id= Array(0,i) then
getDesc =Split((Array(0,i) &","& Array(1,i)),",")
exit for
end if
next
end function
%>