vb+sql 求和值为null时怎么处理?

Adodc3.RecordSource = "select sum(加班时数) as 加班总计 from 表1 where 日期 >=cdate('" & Str(DTP1.Value) & "') and 日期 <=cdate('" & Str(DTP2.Value) & " ') and 加班类型='" & psss & " ' "
Adodc3.Refresh
lblpsss.Caption = Adodc3.Recordset("加班总计").Value
如果数据库中没有找到要求的记录集,结果为空怎么解决?

lblpsss.Caption = cdbl("0" & Adodc3.Recordset("加班总计").Value)
如果为空,与0 相与后再变为数字就成了0,没错
如果不为空,与0 相与后再变为数字还是原来的数字,也没错
当然,你也可以在给标签赋值前先检验记录集,如果为空,则将0赋予标签,不为0则将查询记录赋予标签.
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-06-05
object sum=cmd.ExecuteScalar(s,con);
if(sum==null)
。。
else
...
相似回答