如果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 & "'") '应收款