發(fā)布時(shí)間:2015/8/14 8:01:25 關(guān)注:1658
1 明確查詢的字段名稱
2 使用rs(0)比rs(“name”)更快
3 使用記錄集rs值前,將其賦值給變量
4 [TEST] 現(xiàn)有10W條數(shù)據(jù),Access數(shù)據(jù)庫保存
通過正常提取 | 通過存儲過程提取| 使用GetRows()方法提取:
1 明確查詢的字段名稱
Select * from [data_table]
即從數(shù)據(jù)庫data_table種抽取所有字段的記錄值
Select * 語句的執(zhí)行效率非常低,因?yàn)閳?zhí)行這樣的語句時(shí)執(zhí)行了兩次查詢, 先查詢系統(tǒng)表來確定名稱和數(shù)據(jù)類型.然后再查數(shù)據(jù)
所以精良減少使用select * 語句,而使用明確的字段名稱,如:
Select name,pwd from [data_table]
2 使用rs(0)比rs(“name”)更快
記錄集rs()里面可以寫字段名,或字段索引號.比如
Rs(0)對應(yīng)rs(“name”)
Rs(1)對應(yīng)rs(“pwd”)
已證明用索引數(shù)訪問記錄集要比字段名快出幾倍,按字符串查詢要比按整數(shù)查詢花去的更多的時(shí)間和系統(tǒng)資源
3 使用記錄集rs值前,將其賦值給變量
<%
Set rs=conn.execute(“select cname,cpwd from [data_table] where id=1”)
If not rs.eof then
Do while not rs.eof
Cname=rs(0) 將rs賦值給變量
Cpwd=rs(1)
….
Rs.moveNext
Loop
End if
%>
4 [TEST] 現(xiàn)有10W條數(shù)據(jù),Access數(shù)據(jù)庫保存。
A.通過正常提?。?/strong>
<%
Set rs=server.createObject(“adodb.recordSet”)
Rs.open “select * from people order by id desc”,cn,1,1
Do while not rs.eof
Response.write rs(“id”)&” | ”
Rs.moveNext
loop
%>
耗時(shí)3,250.000毫秒 3秒
B. 通過存儲過程提?。?/strong>
<%
Set cn=server.createObject(“adodb.connection”)
Cn.open “driver={microsoft access driver (*.mdb)};DBQ=”&server.mapPath(“db2.mdb”)
Set cmd=server.createObject(“adodb.command”)
cmd.activeConnection=cn
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
%>
耗時(shí) 2,187.500毫秒 2秒
C.使用GetRows()方法提?。?/u>
<%
Set cn=server.createObject(“adodb.connection”)
Set cmd=server.createObject(“adodb.command”)
Cn.open “driver={microsoft access driver (*.mdb)};DBQ=”&server.mapPath(“db2.mdb”)
cmd.activeConnection=cn
cmd.commandText=”select * from people order by id desc”
set rs=cmd.execute
rsArray=rs.getRows() 將記錄集數(shù)據(jù)存入一個(gè)數(shù)組, 該數(shù)組默認(rèn)為二維數(shù)組
for i=0 to uBound(rsArray,2) Ubound(array,num) 其中num意指數(shù)組維數(shù), 默認(rèn)不填為一維, 2等于二維
response.write rsArray(0,i)&” | ”
next
%>
耗時(shí):187.500毫秒 0.2秒
rsArray(a,b)
a表示存入該數(shù)組記錄集的字段號 b表示存入該數(shù)組記錄集的條數(shù)
如下表:
id | uname | upwd |
RsArray(0,0) | RsArray(1,0) | RsArray(2,0) |
RsArray(0,1) | RsArray(1,1) | RsArray(2,1) |
RsArray(0,2) | RsArray(1,2) | RsArray(2,2) |
地址:山東省濰坊奎文區(qū)新華路樂川街華誼大廈三樓
網(wǎng)址:http://www.aalagrf.cn/ 垂詢電話:
網(wǎng)站備案:魯ICP備14027302號-5
copyright© 濰坊華邦網(wǎng)絡(luò)有限公司2011-2025