|
蓝森林 http://www.lslnet.com 2006年8月25日 8:28
[ASP]SUM求和的问题.
问题的现象:
程序没有错误,输出没有值,是空白的。
以下是程序的代码[code]<%aid=Request.QueryString("aid")
set rs=server.createobject("adodb.recordset")
sql="select sum(prices) as zhy from zhang where aid='"&aid&"' and lb=1"
rs.open sql,conn,1,1
if rs.eof then
jj1=0
else
jj1=rs("zhy")
end if
set rs=server.createobject("adodb.recordset")
sql="select sum(prices) as xfj from zhang where aid='"&aid&"' and lb=0"
rs.open sql,conn,1,1
if rs.bof then
jj2=0
else
jj2=rs("xfj")
end if
rs.close
set rs=nothing
jj3=jj1-jj2
%>
帐户余额:<font color=blue%><%=jj3%></font>
共消费:<font color=red><%=jj2%></font>
[/code]
数据类型说明:aid 是用户名称(文本类型) lb是消费类别(数字类型)
后来发现,数据库全是空的也正常,可以判断不是空的,但是值我设置了为空没有的话就是0,结果用:response.write a 或是 response.write b输出是一片空白, 什么也没有?
在此请教了,搞了半天也没有弄清楚是什么原因。 |
判断bof或者eof的后面你就输出jj1或者jj2就能知道问题了. |
有些错误很微妙的
在执行完第一个数据库的操作时先把recordset关闭一下
试试看 |
在最上边
dim jj1,jj2,jj3
保你好使。 |
[code]
<% dim jj1,jj2,jj3
aid=Request.QueryString("aid")
set rs=server.createobject("adodb.recordset")
sql="select sum(prices) as zhy from zhang where aid='"&aid&"' and lb=1"
rs.open sql,conn,1,1
if rs.eof then
jj1=0
else
jj1=rs("zhy")
end if
rs.close
set rs=nothing
set rs=server.createobject("adodb.recordset")
sql="select sum(prices) as xfj from zhang where aid='"&aid&"' and lb=0"
rs.open sql,conn,1,1
if rs.eof then
jj2=0
else
jj2=rs("xfj")
end if
rs.close
set rs=nothing
jj3=jj1-jj2
%>
帐户余额:<font color=blue%><%=jj3%></font>
共消费:<font color=red><%=jj2%></font>
[/code]
修改后的代码如此,结果还是一样,真郁闷,没查出,程序检测没有错误。 |
会不会是sql语句错误:
sql="select sum(prices) as xfj from zhang where aid='"&aid&"' and lb=0"
|
没一个说对的,kkkk.
你加上这句:
[code]If Not IsNumeric(jj2) Then jj2=0[/code]和
[code]If Not IsNumeric(jj1) Then jj1=0[/code]
这是因为sum得到的要么是数字要么啥也不是, 说你的 判断eof是没用的,就是说怎么都会得到不是eof的,哈哈哈...你试试.
另外,这个sum没必要用建recordset吧,execute算了,哈哈哈....:D
|
谢谢楼上的,终于搞明白了,是的加上这个就OK啦。
开始我加错了,查了一下IsNumeric这个搞明白了。
非常感谢,搞了一上午没明白,换了好多种读法,都不对。
也感谢其它人给我思路。 |
|