We have a dataset dsActualCost which fetches query value: MonthName in one column and Cost in another.
We have a code to display data in table format.
For MonthIndex = 0 To dsMonth.Tables(0).Rows.Count - 1
Dim tdMonthlycost As New TableCell
If dsActualCost.Tables(0).Rows.Count > 0 Then
If IsDBNull(dsActualCost.Tables(0).Rows(MonthIndex).Item(1)) Then
tdMonthlycost.Text = 0
Else
tdMonthlycost.Text = dsActualCost.Tables(0).Rows(MonthIndex).Item(1)
End If
Else
tdMonthlycost.Text = 0
End If
trBody.Cells.Add(tdMonthlycost)
Next
This code works fine when
we have data in all rows
we have no data at all
But it gives exception for all other cases. I tried to debug and issue arises when it searches for any row which is not available in DB.
Say the dataset has only 2 rows for Feb month,so when it executes line
IsDBNull(dsActualCost.Tables(0).Rows(2).Item(1))
It throws Db null exception.
please suggest how should i handle it. the loop will run for 12 months.