【发布时间】:2014-07-30 11:30:58
【问题描述】:
我遇到了上面列出的错误,我在其他地方读到我必须做的是a DBNull-check...,但我不知道该怎么做。我想知道是否有人可以帮助我?我是 VB 的超级新手。
我也尝试将 LedgerId 和 Net 更改为小数,但它告诉我这一行:
JVNet += Net
错了。 “+ 对 DBNull 和小数无效”之类的内容。
这是相关代码(我认为)。
Dim SQLStmt, LedgerId, NetDisp As String
Dim Net, JVNet As Decimal
Dim NetCounter As Integer
Cnxn.Open()
SQLStmt = "SELECT LedgerId, sum(Qty * Each) as Net FROM Orders, Details where CONVERT(nvarchar(10), AcctgDate, 101) = '" & _
cbJVDate.Text & _
"' and Orders.Id = Details.OrderId group by LedgerId order by LedgerId"
Dim JVCommand As New SqlCeCommand(SQLStmt, Cnxn)
Dim JVReader As SqlCeDataReader
lblAdvice.Text = ""
Debug.Print(vbCrLf & "Got Here with '" & SQLStmt & "'" & vbCrLf)
Try
JVReader = JVCommand.ExecuteReader
Catch ex As Exception
MsgBox("Execute JVReader with '" & SQLStmt & "' got " & ex.Message)
Exit Sub
End Try
JVNet = 0
NetCounter = 0
lbJournal.Items.Clear()
Do While JVReader.Read()
LedgerId = JVReader.Item("LedgerId")
Net = JVReader.Item("Net")
JVNet += Net
NetCounter += 1
NetDisp = Format(Net, "0.00;(0.00)")
NetDisp = NetDisp.PadLeft(10, " ")
If Net < 0 Then NetDisp = " " & NetDisp
lbJournal.Items.Add(LedgerId & NetDisp)
Loop
If NetCounter = 0 Then
lblAdvice.ForeColor = Color.DarkRed
lblAdvice.Text = "There are no details posted for " & cbJVDate.Text & "..."
ElseIf JVNet = 0 Then
lblAdvice.ForeColor = Color.Black
lblAdvice.Text = "The journal for this date nets zero."
Else
lblAdvice.ForeColor = Color.DarkRed
lblAdvice.Text = "The journal for this date does not net zero." & vbCrLf & _
vbCrLf & "It nets " & Format(JVNet, "0.00")
End If
Cnxn.Close()
End Sub
感谢您的帮助!
【问题讨论】:
-
为了澄清,您使用的是 SQL CE 对吗?如果是这样,SQL CE 不支持 IFNULL 或 ISNULL 函数。
-
是的,我们是。感谢您为我澄清这一点!