Question : Checking a Dataset for DBNull whiclst using the Compute SUM function

Hi All
I am using a Dataset's Compute function but get the error 'Object cannot be cast from DBNull '. Obviously there is no data being returned with the TYPE_ID 1.Please could you let me know how I could check the the returning SUM for DBNull...

ds.Tables("reporttbl").Compute("SUM(TOTAL_MONTH_WEIGHT)", "TYPE_ID=1")

Many thanks

Rit

Answer : Checking a Dataset for DBNull whiclst using the Compute SUM function

...did you resolve this?
what about something like:

        Dim conftotal As Double = 0.0
        Dim dtConf As DataTable = ds.Tables("reporttbl") 'use a datatable instead of dataview

        dtConf.Select("TYPE_ID=1") 'filter the datatable
        For i As Integer = 0 To dtConf.Rows.Count - 1 'loop through rows
            If IsDBNull(dtConf.Rows(i)("TOTAL_MONTH_WEIGHT")) = False Then 'make sure it isn't null
                If IsNumeric(dtConf.Rows(i)("TOTAL_MONTH_WEIGHT")) = True Then 'make sure it's a number
                    conftotal += CType(dtConf.Rows(i)("TOTAL_MONTH_WEIGHT"), Double) 'add it to the total
                End If
            End If
        Next
Random Solutions  
 
programming4us programming4us