First of all, a little pointer because you are making life difficult for
yourself.
The Item property of the Rows collection of a DataTable is the default
property so you don't have to code:
ds.Tables(0).Rows.Item(i)
Rather, you can simply code:
ds.Tables(0).Rows(i)
Similarly, the default property of a DataRow is DataColumns (or Columns) and
the default property of a DataColumn (or Column) is Value. Therefore it is
simpler to code:
Name = ds.Tables(0).Rows(i)(1)
Assuming Name is a String, then because the Value property returns an Object
you will need to cast it accordingly:
Name = CType(ds.Tables(0).Rows(i)(1), String)
Now this is where DbNull's rear their ugly head because you can't cast a
DbNull to a String (or any other type for that matter.
What you have to do is determine your business rule for handling DbNull.
If, for instance, you decide that (for a String) dbNull should beconverted
to an empty string then you can use:
Name = String.Empty
If Not IsDbNull(ds.Tables(0).Rows(i)(1)) Then Name =
CType(ds.Tables(0).Rows(i)(1), String)
As a variation you couild could also use:
If ds.Tables(0).Rows(i)(1) <> DbNull.Value Then Name =
CType(ds.Tables(0).Rows(i)(1), String)
That is really a matter of personal preference but whichever you use it must
fit in your comfort zone.
For Tom, the IsDbNull certainly does work in Framework 2.0 but the IsNull
function will certainly NOT work in relation to DbNull's.
The secret is to make sure you learn the difference between DbNull.Value and
Nothing which are completely different things.