关于asp中读取数据库记录总数
来源:百度知道 编辑:UC知道 时间:2024/05/30 20:21:05
要求最节省服务器资源的读取方法
我用的是
<!-- #include file="conn.asp" -->
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open StrConn
cmd="select count(ID) as num from accept_sheet where restored='no' and accept_del='no'
Set rs1 = Conn.Execute( cmd )
if rs1.eof then
rs1_recordcount=0
Else
rs1_recordcount=rs1("num")
End if
rs1.close
set rs1=nothing
rs1_recordcount=conn.execute("select count(ID) from accept_sheet where restored='no' and accept_del='n")(0)
(0)是为什么?
我用的是
<!-- #include file="conn.asp" -->
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open StrConn
cmd="select count(ID) as num from accept_sheet where restored='no' and accept_del='no'
Set rs1 = Conn.Execute( cmd )
if rs1.eof then
rs1_recordcount=0
Else
rs1_recordcount=rs1("num")
End if
rs1.close
set rs1=nothing
rs1_recordcount=conn.execute("select count(ID) from accept_sheet where restored='no' and accept_del='n")(0)
(0)是为什么?
rs.recordcount 直接返回记录总数
你在SQL中使用count(ID) as num ,不也一样是操作数据库自己计算吗,对服务器而言,一样执行了该命令
所以,直接用rs.recordcount,不存在效率问题
你是不是在你的conn.asp中已经打开了你的连接??你又来打开是不是出错了喃?
rs1_recordcount=conn.execute("select count(ID) from accept_sheet where restored='no' and accept_del='n")(0)