Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Checking for DBNull in DataTable
Message
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Titre:
Checking for DBNull in DataTable
Divers
Thread ID:
00887448
Message ID:
00887448
Vues:
52
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform