By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,635 Members | 2,174 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,635 IT Pros & Developers. It's quick & easy.

Typed DataSet: "Cannot get value because it is DBNull": Why still using it?

P: n/a
Hi,

Something I don't understand about a Typed DataSet: When a value in the
DataSet is DBNull, it throws this error: "Cannot get value because it is
DBNull".

But aren't Typed DataSets invented to make life easier, to be able to get to
tge Tables and Values with less code, in less time? But with this thing you
need to add a Try-Catch around every statement when using the value, add for
each value a default value in your DataSet (and you have to redo it each
time something changes to your DataSet!), or don't allow Null-values in any
of your Tables in your Sql Server..

So why are people still using these things? Did anybody find an easy, fast
and good working solution to get around this problem?

Pieter
Jul 22 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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
need/want nulls give the DataColumn a defaultvalue and set allowdbnull to
false.
You can also use the untyped indexer of the datarow which will return what
is in the row regardless which type and wheather it is null or not.

And one important thing: please do not crosspost, this is inpolite.

Hope it helps.
"DraguVaso" <pi**********@hotmail.com> schrieb im Newsbeitrag
news:#D**************@TK2MSFTNGP10.phx.gbl...
Hi,

Something I don't understand about a Typed DataSet: When a value in the
DataSet is DBNull, it throws this error: "Cannot get value because it is
DBNull".

But aren't Typed DataSets invented to make life easier, to be able to get to tge Tables and Values with less code, in less time? But with this thing you need to add a Try-Catch around every statement when using the value, add for each value a default value in your DataSet (and you have to redo it each
time something changes to your DataSet!), or don't allow Null-values in any of your Tables in your Sql Server..

So why are people still using these things? Did anybody find an easy, fast
and good working solution to get around this problem?

Pieter

Jul 22 '05 #2

P: n/a
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.

"cody" <de********@gmx.de> wrote in message
news:OR**************@TK2MSFTNGP14.phx.gbl...
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
need/want nulls give the DataColumn a defaultvalue and set allowdbnull to
false.
You can also use the untyped indexer of the datarow which will return what
is in the row regardless which type and wheather it is null or not.

And one important thing: please do not crosspost, this is inpolite.

Hope it helps.
"DraguVaso" <pi**********@hotmail.com> schrieb im Newsbeitrag
news:#D**************@TK2MSFTNGP10.phx.gbl...
Hi,

Something I don't understand about a Typed DataSet: When a value in the
DataSet is DBNull, it throws this error: "Cannot get value because it is
DBNull".

But aren't Typed DataSets invented to make life easier, to be able to get
to
tge Tables and Values with less code, in less time? But with this thing

you
need to add a Try-Catch around every statement when using the value, add

for
each value a default value in your DataSet (and you have to redo it each
time something changes to your DataSet!), or don't allow Null-values in

any
of your Tables in your Sql Server..

So why are people still using these things? Did anybody find an easy,

fast and good working solution to get around this problem?

Pieter


Jul 22 '05 #3

P: n/a
Hi Dragu,

Every nullable column in typed dataset has an Is[ColumnName]Null() method.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group www.codezone-si.info

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

Something I don't understand about a Typed DataSet: When a value in the
DataSet is DBNull, it throws this error: "Cannot get value because it is
DBNull".

But aren't Typed DataSets invented to make life easier, to be able to get
to
tge Tables and Values with less code, in less time? But with this thing
you
need to add a Try-Catch around every statement when using the value, add
for
each value a default value in your DataSet (and you have to redo it each
time something changes to your DataSet!), or don't allow Null-values in
any
of your Tables in your Sql Server..

So why are people still using these things? Did anybody find an easy, fast
and good working solution to get around this problem?

Pieter

Jul 22 '05 #4

P: n/a
Thanks! That solves my problem I guess :-)

"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:uw**************@TK2MSFTNGP14.phx.gbl...
Hi Dragu,

Every nullable column in typed dataset has an Is[ColumnName]Null() method.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group www.codezone-si.info

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

Something I don't understand about a Typed DataSet: When a value in the
DataSet is DBNull, it throws this error: "Cannot get value because it is
DBNull".

But aren't Typed DataSets invented to make life easier, to be able to get to
tge Tables and Values with less code, in less time? But with this thing
you
need to add a Try-Catch around every statement when using the value, add
for
each value a default value in your DataSet (and you have to redo it each
time something changes to your DataSet!), or don't allow Null-values in
any
of your Tables in your Sql Server..

So why are people still using these things? Did anybody find an easy, fast and good working solution to get around this problem?

Pieter


Jul 22 '05 #5

P: n/a
On Thu, 14 Jul 2005 15:23:36 +0200, DraguVaso wrote:
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?
Jul 22 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.