現有10W條數據,Access數據庫保存
通過正常提取:
<%
Set conn= Server.CreateObject("ADODB.Connection")
connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("db2.mdb")
conn.Open connstr
Set rs = Server.CreateObject ("ADODB.Recordset")
sql = "Select * from people order by id desc"
rs.Open sql,conn,1,1
Do While Not rs.EOF
Response.write rs("id")&" | "
rs.MoveNext
Loop
%>
http://www.cnbruce.com/test/getrows/show1.asp
耗時3,250.000毫秒,總測試平均值在3秒左右==========================================================
使用存儲過程提取:
<%
Set conn = Server.CreateObject("ADODB.Connection")
Set cmd = Server.CreateObject("ADODB.Command")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db2.mdb")
cmd.ActiveConnection = conn
cmd.CommandText = "Select * from people order by id desc"
Set rs = cmd.Execute
Do While Not rs.EOF
Response.write rs("id")&" | "
rs.MoveNext
Loop
%>
http://www.cnbruce.com/test/getrows/show2.asp
耗時2,187.500毫秒,總測試平均值在2秒左右=========================================================
以上兩種均不能徹底解決執行時間漫長的問題,主要原因即是循環每次都須向數據庫抽取記錄(Command速度相對較快)
那麼使用GetRows()方法呢:
<%
Set conn = Server.CreateObject("ADODB.Connection")
Set cmd = Server.CreateObject("ADODB.Command")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db2.mdb")
cmd.ActiveConnection = conn
cmd.CommandText = "Select * from people order by id desc"
Set rs = cmd.Execute
rsArray = rs.GetRows()
For i = 0 To UBound(rsArray, 2)
Response.Write rsArray(0, i)&" | "
Next
%>
http://www.cnbruce.com/test/getrows/show3.asp
耗時187.500毫秒,總測試平均值在0.2秒左右GetRows()方法是將數據從 Recordset 復制到二維數組中,這是一個二維數組,第一個下標標識字段,第二個則標識記錄號
所以rsArray = rs.GetRows()
rsArray(0, 0)就表示記錄集第一行的第一字段值
rsArray(1, 0)就表示記錄集第一行的第二字段值
數組的數據是保存在內存中的,這就從根本上解決了每次顯示記錄還需向數據庫請求的麻煩。
另外,關於GetRows()的詳細介紹和用法,這裡有份內容參考
http://www.51windows.net/pages/Ado/mdmthgetrows.htm
http://www.blueidea.com/tech/program/2005/2853.asp