Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Checking for DBNull in DataTable
Message
General information
Forum:
ASP.NET
Category:
ADO.NET
Title:
Checking for DBNull in DataTable
Miscellaneous
Thread ID:
00887448
Message ID:
00887448
Views:
51
I've filled a DataTable with the contents of a number of specified rows, and am having problems displaying the NULL values

Some fields contain Null, or Bit logic

and running something like the following causes an exception

Option Strict is ON

Dim col As DataColumn
For Each col In dt.Columns
Console.WriteLine(col.ColumnName & " - " _
& col.DataType.ToString & " : " & _
CType(row(col), String))
Next

It can be traped for using something like the code below:-

if row(col).GetType().ToString = "System.DBNull" Then
Console.WriteLine(col.ColumnName & " - " _
& col.DataType.ToString & " : Null")
Else
Console.WriteLine(col.ColumnName & " - " _
& col.DataType.ToString & " : " & _
CType(row(col), String))
End IF


but this does not seem to me to be the correct solution, what is the correct way for doing this. I've simplified the code that I'm actually using - I also getting similiar problems trapping for "System.Byte[]"

Hope someone can tell me how stupid I am, as you may guess I pretty new to VB.NET
John T Barton
A single picture (or bit of code) is worth a thousand words
Next
Reply
Map
View

Click here to load this message in the networking platform