<% ' 数据库连接信息 Dim conn, connStr Set conn = Server.CreateObject("ADODB.Connection") connStr = "Provider=SQLOLEDB;Data Source=(local);Initial Catalog=db;User ID=sa;Password=123456;" conn.Open connStr ' 父类SQL语句 Dim parentSQL, parentRS parentSQL = "select id,MingCheng from BDClass where ParentID='1' order by orders" 'conn.CursorLocation = adUseClient 'Set parentRS = conn.Execute(parentSQL) 'parentRS.cursorlocation=3 Set parentRS = Server.CreateObject("ADODB.Recordset") parentRS.Open parentSQL,conn,3,2 ' 定义父类和子类数组 Dim parentArray, childArray Dim parentIndex, childIndex parentIndex = 0 ReDim parentArray(parentRS.RecordCount - 1, 1) ' 循环父类数据 Do While Not parentRS.EOF ' 保存父类数据到数组 parentArray(parentIndex, 0) = parentRS("id") parentArray(parentIndex, 1) = parentRS("MingCheng") ' 子类SQL语句 Dim childSQL, childRS childSQL = "select C.Comid,C.Title,C.OutUrl,C.TJtitle,C.Logo,C.ZSstar from BDcompany T,Company C where T.Comid=C.Comid and C.IsPass=1 and T.classid='" & parentRS("id") & "' order by Orders ,T.AddTime desc,T.ID desc" 'Set childRS = conn.Execute(childSQL) Set childRS = Server.CreateObject("ADODB.Recordset") childRS.Open childSQL,conn,3,2 ' 初始化子类数组 childIndex = 0 ReDim childArray(childRS.RecordCount - 1, 5) ' 循环子类数据 Do While Not childRS.EOF ' 保存子类数据到数组 childArray(childIndex, 0) = childRS("Comid") childArray(childIndex, 1) = childRS("Title") childArray(childIndex, 2) = childRS("OutUrl") childArray(childIndex, 3) = childRS("TJtitle") childArray(childIndex, 4) = childRS("Logo") childArray(childIndex, 5) = childRS("ZSstar") childIndex = childIndex + 1 childRS.MoveNext Loop ' 关闭子类记录集 childRS.Close Set childRS = Nothing ' 可以在这里使用子类数组进行其他操作,例如输出或处理 parentIndex = parentIndex + 1 parentRS.MoveNext Loop ' 关闭父类记录集和数据库连接 parentRS.Close Set parentRS = Nothing conn.Close Set conn = Nothing ' 可以在这里使用父类数组进行其他操作,例如输出或处理 Response.Write "<h2>所有父类信息:</h2>" Response.Write "<ul>" For i = LBound(parentArray, 1) To UBound(parentArray, 1) Response.Write "<li>父类ID: " & parentArray(i, 0) & ", 父类名称: " & parentArray(i, 1) & "</li>" Next Response.Write "</ul>" %>