I have been looking for a solution to this problem for a while now and am feeling really stuck; I can find solutions to problems that are similar, but not the same as mine.
I am pulling data from a local MSSQL database using a stored procedure, then send the data to a web service. Every part of the component works well except for a pesky problem will a DBNull being returned from the DataRow field, when I know that the field is not null and has valid data. The database and associated INSERT statements that add to this field are designed to not allow NULL entries. When I debug break the program on or right before the line that throws the error I see that the field has valid data for the current row.
If I add a null check to the code (as below) the operation continues as normal:
Dim dataResultsTable = Me.myViewTableAdapter.GetData(int)
For Each myDataRow In dataResultsTable.Rows
If worker.CancellationPending Then
e.Cancel = True
Else
If myDataRow.Item("syncd") = 0 Then
If IsDBNull(myDataRow.Item("bidamount")) Then
_bidAmt = ""
Else
// With out the null check this line throws an error
_bidAmt = myDataRow.Item("bidamount")
End If
If IsDBNull(myDataRow.Item("date_time")) Then
_dateTime = ""
Else
// With out the null check this line throws an error
_dateTime = myDataRow.Item("date_time")
End If
// . . . . . . . .
worker.ReportProgress(percentcomplete)
End If
End If
Next
The question here is: Why is the read operation returning DBNull instead of the data in the database? Any and all help here is much appreciated!
EDIT: Just to be clear, the operation does return the proper data, but the data is not being saved into the variable.
Exit Forafter thee.Cancel = TrueIf worker.CancellationPending Thenstatement, and then expand the value of thedataResultsTablevariable I see that those fields that throw an error has values in them. I'm stumped on this one, it should work by all accounts that I can see. (Only come across this situation once before)