Foxtable(狐表)用户栏目专家坐堂 → [求助]SQLCommand语名返回多个值时出错


  共有6995人关注过本帖树形打印复制链接

主题:[求助]SQLCommand语名返回多个值时出错

帅哥哟,离线,有人找我吗?
2425004926
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:712 积分:5559 威望:0 精华:0 注册:2019/11/14 9:36:00
[求助]SQLCommand语名返回多个值时出错  发帖心情 Post By:2022/9/3 11:28:00 [显示全部帖子]

如果f2查询后的行不存在时,报错从类型“DBNull”到类型“Integer”的转换无效。如查询行存在时一切正常

Dim cmd As New SQLCommand
cmd.C
'------------------------------------------------------------------------------- 批量定义
Dim Val11, Val14, Val15, Val16 As Integer
'------------------------------------------------------------------------------- 统计
Dim f1 As String = "Possessor = '" & _UserName & "'"
Dim f2 As String = "HowMany = 11" & " And Possessor = '" & _UserName & "'"
cmd.CommandText = "Select Count( * ) As 合同数量, Sum(TotalMoney) As 金额, Sum(AdvancePayment) As 已收款, Sum(AccountReceivable) As 应收款 Fr om {UserExhibitors} Where " & f2
Dim Values = cmd.ExecuteValues
If Values.Count > 0 Then
MessageBox.Show("可以通过"),后报错从类型“DBNull”到类型“Integer”的转换无效。查询的行不存在时,发现Count > 0没有起作用
    Val11 = Values("合同数量")
    Val14 = Values("金额")
    Val15 = Values("已收款")
    Val16 = Values("应收款")
MessageBox.Show("不能通过")
End If

'但是用下面的方法可以正常统计,可是要先加载表,上面的方法优势是不用加载表
Val11 = DataTables("UserExhibitors").SQLCompute("Count(*)", "HowMany = '" & jie & "' And Possessor = '" & _UserName & "'") '合同数量
Val14 = DataTables("UserExhibitors").SQLCompute("Sum(TotalMoney)", "HowMany = '" & jie & "' And Possessor = '" & _UserName & "'") '金额
Val15 = DataTables("UserExhibitors").SQLCompute("Sum(AdvancePayment)", "HowMany = '" & jie & "' And Possessor = '" & _UserName & "'") '已收款
Val16 = DataTables("UserExhibitors").SQLCompute("Sum(AccountReceivable)", "HowMany = '" & jie & "' And Possessor = '" & _UserName & "'") '应收款

 回到顶部
帅哥哟,离线,有人找我吗?
2425004926
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:712 积分:5559 威望:0 精华:0 注册:2019/11/14 9:36:00
  发帖心情 Post By:2022/9/3 12:33:00 [显示全部帖子]

 OK,谢谢老师!!!

 回到顶部