我用asp求记录集总数的时候。咋子老是显示-1条嘛,明明有很多条的
语句是这样的
<%dim rsnewtype,newstype
newstype = request("idd")
set rsnewtype = server.CreateObject("adodb.recordset")
rsnewtype.open "select * from news where newstype='"&newstype&"'",cn
%>
<%=rsnewtype.recordcount%>
帮我一下哇~~
asp 记录集总数
答案:3 悬赏:30 手机版
解决时间 2021-03-03 01:19
- 提问者网友:动次大次蹦擦擦
- 2021-03-02 07:41
最佳答案
- 五星知识达人网友:长青诗
- 2021-03-02 08:33
数据库操作步骤应该是:
创建链接对象,打开数据库,创建记录集对象,从表中选择记录集,
数据操作,关闭操作.
<%
dim cn,connstr,rsnewtype,newstype,rsstr
Set cn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(dbfile)'dbfile是你的数据库
cn.Open connstr
set rsnewtype = server.CreateObject("adodb.recordset")
rsstr="select * from news where newstype='"&newstype&"'"
rsnewtype.open rsstr,cn,1,3
%>
<%=rsnewtype.recordcount%>
<%
rsnewtype.close
set rsnewtype=nothing
cn.close
set cn=nothing
%>
另外,下面有问题:
newstype = request("idd")
改成:newstype = request.querystring("idd")
创建链接对象,打开数据库,创建记录集对象,从表中选择记录集,
数据操作,关闭操作.
<%
dim cn,connstr,rsnewtype,newstype,rsstr
Set cn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(dbfile)'dbfile是你的数据库
cn.Open connstr
set rsnewtype = server.CreateObject("adodb.recordset")
rsstr="select * from news where newstype='"&newstype&"'"
rsnewtype.open rsstr,cn,1,3
%>
<%=rsnewtype.recordcount%>
<%
rsnewtype.close
set rsnewtype=nothing
cn.close
set cn=nothing
%>
另外,下面有问题:
newstype = request("idd")
改成:newstype = request.querystring("idd")
全部回答
- 1楼网友:鱼芗
- 2021-03-02 10:57
rsnewtype.open "select * from news where newstype='"&newstype&"'",cn,1,3
- 2楼网友:鱼忧
- 2021-03-02 10:04
光有包含文件名是没有用的,还得有数据库连接对象名,才行,自己打开conn.asp查找
set conn=server.createobject("adodb.connection"),这句,看看set后面是不是conn不是的话自己修改一下,这里代码假设连接对象是conn,而且,没有说明这三个字段是什么类型的,如果是text字段,还需判断是否为非null的空字符串,则sql语句需做相应修改。
以下是完整代码
302 Found
302 Found
nginx
<%
dim sql,rs,yjscount,ynscount,yyscount
set rs=server.createobject("adodb.recordset")
sql="select count(*) as rcount from tongji where not yjs is null"
rs.open sql,conn,1,1
yjscount = rs("rcount")
rs.close
sql="select count(*) as rcount from tongji where not yns is null"
rs.open sql,conn,1,1
yjscount = rs("rcount")
rs.close
sql="select count(*) as rcount from tongji where not yys is null"
rs.open sql,conn,1,1
yjscount = rs("rcount")
rs.close
set rs=nothing
response.write("yjs字段不为空记录数:" & yjscount & "
")
response.write("yns字段不为空记录数:" & ynscount & "
")
response.write("yys字段不为空记录数:" & yyscount & "
")
%>
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯