現(xiàn)有10W條數(shù)據(jù),Access數(shù)據(jù)庫保存
通過正常提?。?nbsp;
復(fù)制代碼 代碼如下:
%
Set conn= Server.CreateObject("ADODB.Connection")
cServer.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秒左右
==========================================================
使用存儲過程提?。?nbsp;
復(fù)制代碼 代碼如下:
%
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秒左右
=========================================================
以上兩種均不能徹底解決執(zhí)行時間漫長的問題,主要原因即是循環(huán)每次都須向數(shù)據(jù)庫抽取記錄(Command速度相對較快)
那么使用GetRows()方法呢:
復(fù)制代碼 代碼如下:
%
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()方法是將數(shù)據(jù)從 Recordset 復(fù)制到二維數(shù)組中,這是一個二維數(shù)組,第一個下標(biāo)標(biāo)識字段,第二個則標(biāo)識記錄號
所以rsArray = rs.GetRows()
rsArray(0, 0)就表示記錄集第一行的第一字段值
rsArray(1, 0)就表示記錄集第一行的第二字段值
數(shù)組的數(shù)據(jù)是保存在內(nèi)存中的,這就從根本上解決了每次顯示記錄還需向數(shù)據(jù)庫請求的麻煩。