抽取10萬條數(shù)據(jù),想起GetRows()
更新時間:2006年12月17日 00:00:00 作者:
現(xiàn)有10W條數(shù)據(jù),Access數(shù)據(jù)庫保存
通過正常提?。?br>
http://www.cnbruce.com/test/getrows/show1.asp
耗時3,250.000毫秒,總測試平均值在3秒左右
==========================================================
使用存儲過程提?。?br>
http://www.cnbruce.com/test/getrows/show2.asp
耗時2,187.500毫秒,總測試平均值在2秒左右
=========================================================
以上兩種均不能徹底解決執(zhí)行時間漫長的問題,主要原因即是循環(huán)每次都須向數(shù)據(jù)庫抽取記錄(Command速度相對較快)
那么使用GetRows()方法呢:
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ù)庫請求的麻煩。
另外,關(guān)于GetRows()的詳細(xì)介紹和用法,這里有份內(nèi)容參考
http://www.51windows.net/pages/Ado/mdmthgetrows.htm
http://www.blueidea.com/tech/program/2005/2853.asp
通過正常提?。?br>
<% 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秒左右
==========================================================
使用存儲過程提?。?br>
<% 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()方法呢:
<% 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ù)庫請求的麻煩。
另外,關(guān)于GetRows()的詳細(xì)介紹和用法,這里有份內(nèi)容參考
http://www.51windows.net/pages/Ado/mdmthgetrows.htm
http://www.blueidea.com/tech/program/2005/2853.asp
相關(guān)文章
ASP+MSSQL2000 數(shù)據(jù)庫被批量注入后的解決方法
這陣子,采用ASP+MSSQL設(shè)計的很多網(wǎng)站可能遭遇到sql數(shù)據(jù)庫被掛馬者插入JS木馬的經(jīng)歷;這不,朋友的一個網(wǎng)站就被黑客忽悠了一把2009-02-02
asp教程中g(shù)et post提交表單有5點區(qū)別
asp教程中g(shù)et post提交表單有5點區(qū)別分別以HTTP請求,表單兩者分別介紹,需要的朋友可以了解下2012-12-12
ASP動態(tài)級聯(lián)菜單實現(xiàn)代碼
asp級聯(lián)菜單效果代碼2008-04-04
使用innerHTML時注意處理空格和回車符(asp后臺處理)
innerHTML中如果包含空格和回車都會被認(rèn)為是段落的結(jié)束,造成程序運(yùn)行出錯,解決辦法,輸出的時候?qū)⒖崭窈突剀囂鎿Q掉,方便js調(diào)用。2011-08-08

