Sub GetRecordSet(strBbmc,strKssj , strZzsj ,strNodeCode ,strFxzl ) '参数为报表名称和各个限制条件 select case strBbmc case “交易汇总表" strCnn=“PROVIDER=MSDASQL;dsn=sqldb; uid=sa;pwd=123456;database=vlog;" Set objcnn=Server.CreateObje(“ADODB.Connection") objcnn.CommandTimeout = 9999999 objcnn.ConnectionTimeout = 99999999 objcnn.CursorLocation = adUseClient objcnn.Open strCnn '打开连接 Set objRs =Server.CreateObject (“ADODB.Recordset") objRS.PageSize = iPageSize objRS.CacheSize = iPageSize objRs.Open “sszhatmlog ‘“ & strKssj & "' , ‘“ & strZzsj & "', ‘“ & strNodeCode & "' , ‘“ & strFxzl & "'",objcnn,adOpenStatic , adLockReadOnly,1 ’执行存储过程返回查询结果 ...... End Sub
3.将查询结果保存到动态数组
Sub SaveRecordSet() if objRs.EOF = false then objRs.movelast session(“iRowCount") = objRs.recordCount session(“iFieldCount") = objRs.Fields.Count session(“iPageCount") = objRs.pagecount redim Preserve TempArray(session (“iRowCount"),session(“iFieldCount")) ’TempArray是一个二维动态数组, 根据记录集大小重新定义其大小 objRs.MoveFirst iCount=0 do while objRs.EOF=false iCount = iCount + 1 for i= 1 to session(“iFieldCount") TempArray(iCount,i)=objRs.Fields.Item (i-1).value next objRs.MoveNext loop session(“StoredArray") = TempArray objRs.Close else session(“iPageCount") = 0 end if End Sub
4.显示记录内容
Sub ShowRecord() ...... LocalArray=session(“StoredArray") iShowTotal=(iPageCurrent-1)*iPageSize+1 iRowLoop = 1 do while iRowLoop < = iPageSize and iShowTotal < = session(“iRowCount") Response.Write(“< TR >") for i = 1 To session(“iFieldCount") Response.write(“< TD >" & LocalArray(iShowTotal,i)) Next Response.Write(“< /TR >") iShowTotal = iShowTotal + 1 iRowLoop = iRowLoop + 1 loop Response.Write(“< /TABLE >") if iPageCurrent < > 1 and iPageCurrent < session (“iPageCount") then % > < center >< A HREF=“db_pag.asp?page=< %= iPageCurrent - 1 % >" >前一页< /A >< A HREF= “db_pag.asp?page=< %= iPageCurrent + 1 % >" > 后一页< /A >< /center > < % else if iPageCurrent < > 1 then % > < center >< A HREF=“db_pag.asp?page=< %= iPageCurrent - 1 % >" >前一页 < /A >< /center > < % end if if iPageCurrent < session(“iPageCount")then % > < center >< A HREF=“db_pag.asp?page= < %= iPageCurrent + 1 % >" >后一页 < /A > < /center > < % end if end if End Sub
5.主程序
if Request.QueryString(“page") = “" then ’提交查询申请并且查询条件与上一次不同 ...... call GetRecordSet(strBbmc,strKssj,strZzsj, strNodeCode,strFxzl) call SaveRecordSet Else iPageCurrent=CInt(Request.QueryString(“page")) strKssj=session(“strKssj") end if if session(“iPageCount") = 0 then Response.Write “抱歉!没有满足条件的记录" Response.Write “< Br >" else call showrecord() end if