Well, I expect it to return DBNull, and not an error! DBNull is actually
also some kind of value, so throwing an exception isn't really a nice thing
in my opinion, hehe :-) When using the Untyped DataSet it returns DBNull
too, so i don't see a reason why they have changed this with a Typed
DataSet...
And yes indeed you can use the untyped indexer every time: but again: why
use a Typed DataSet if you need to call everytime the untyped to read the
value's? It jsut doesn't make any sense to me :-(
Pieter
PS: I didn't croospost this? I just send it to 4 newgroups that seem
logically concerned to this: framework, adonet (it has something to do with
it), vb (which I uses), general (because it happens in other languages too).
But anyways my apologizes if I harmed anybody with this.
> If the value in the dataset is null what do you expect the getter to return?
> How do you expect they will cast DBNull in, say, int? If you do not
[quoted text clipped - 28 lines]
> >
> > Pieter
Ross Presser - 14 Jul 2005 16:33 GMT
> Well, I expect it to return DBNull, and not an error! DBNull is actually
> also some kind of value, so throwing an exception isn't really a nice thing
> in my opinion, hehe :-)
DBNull is a kind of value. But it is not convertible to int, string, or
anything else. The declaration of the properties are that they return the
types given. An example from one of my typed datasets:
Public Property label As String
Get
Try
Return CType(Me(Me.tableVariablepg.labelColumn),String)
Catch e As InvalidCastException
Throw New StrongTypingException( _
"Cannot get value because it is DBNull.", e)
End Try
End Get
Set
Me(Me.tableVariablepg.labelColumn) = value
End Set
End Property
Now, if the label property must return a string, then you can't return
DBNull.Value. Just try it in code - the compiler won't even let you.
Insert "return dbnull.value" below the catch statement, and watch the nice
wiggly blue line appear underneath it.
> When using the Untyped DataSet it returns DBNull
> too, so i don't see a reason why they have changed this with a Typed
> DataSet...
When you use an untyped dataset, it returns an Object type. When you use a
typed dataset, it returns a type. Simple.
What are you going to do in the code when the value is null? You're going
to do something special. So why not check IsNull() beforehand anyway?