Cannot unbox as Decimal RRS feed

  • Question

  • User2098947605 posted

    I've got the following code that is kicking out the error in the subject line.  It works fine when a value is returned from the database, however, if I try to return 0 because no rows were returned from the database, I get the error in the subject line.

    Any ideas anyone?

    <asp:Label ID="lblTotExpend" runat="server" style="text-align:right;" Text='<%# string.Format("{0:c}",(decimal) BO.TotPayments(CurrentID, ref msError))%>'></asp:Label>

    TotPayments() is a VB method that returns an object that contains a SQL decimal value.

    function TotPayments(sID as string, byref sErr as string) as object

    'query db

    dim v = dt.rows(0).item("value")

    if v is nothing then

      v = 0 ' this causes the error in the subject line. 

    end if

    return v

    end function


    Tuesday, September 9, 2008 6:53 PM

All replies

  • User1330954201 posted


    Could you not just return a decimal? E.g. :-  

    Function TotPayments(ByVal sID As String, ByRef sErr As String) As Decimal

    'query db

    Dim v As Decimal

    If Not IsDBNull(dt.Rows(0).Item("value")) Then

    v = CDec(dt.Rows(0).Item("value"))


    v = 0.0

    End If

    Return v

    End Function


    Wednesday, September 10, 2008 11:39 AM