1 明確查詢的字段名稱
2 使用rs(0)比rs(name)更快
3 使用記錄集rs值前,將其賦值給變量
4 [TEST] 現有10W條數據,Access數據庫保存
通過正常提取| 通過存儲過程提取| 使用GetRows()方法提取:
1 明確查詢的字段名稱
Select * from [data_table]
即從數據庫data_table種抽取所有字段的記錄值
Select * 語句的執行效率非常低,因為執行這樣的語句時執行了兩次查詢, 先查詢系統表來確定名稱和數據類型.然後再查數據
所以精良減少使用select * 語句,而使用明確的字段名稱,如:
Select name,pwd from [data_table]
2 使用rs(0)比rs(name)更快
記錄集rs()裡面可以寫字段名,或字段索引號.比如
Rs(0)對應rs(name)
Rs(1)對應rs(pwd)
已證明用索引數訪問記錄集要比字段名快出幾倍,按字符串查詢要比按整數查詢花去的更多的時間和系統資源
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] 現有10W條數據,Access數據庫保存。
A.通過正常提取:
<%
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
%>
耗時3,250.000毫秒3秒
B.通過存儲過程提取:
<%
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
%>
耗時2,187.500毫秒2秒
C.使用GetRows()方法提取:
<%
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()將記錄集數據存入一個數組, 該數組默認為二維數組
for i=0 to uBound(rsArray,2) Ubound(array,num) 其中num意指數組維數, 默認不填為一維, 2等於二維
response.write rsArray(0,i) & |
next
%>
耗時:187.500毫秒0.2秒
rsArray(a,b)
a表示存入該數組記錄集的字段號b表示存入該數組記錄集的條數
如下表:
| 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) |