472,331 Members | 1,627 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 software developers and data experts.

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

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
5 7294
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Pavils Jurjans | last post by:
Hello, I am building custom hashtable class, and thinking about value retrieval issues. The thing is, that sometimes the hashtable value may...
3
by: Karunakararao | last post by:
Hi all Presently i am sending data to database filed like this "EquipmentFilterDevPrimaryId = 0" i need Instead of "0" (NULL)i need store...
4
by: charliewest | last post by:
I need to set the selected drop down list value at run time. I am aware of the method "SelectIndex" however this works only if you know the precise...
1
by: Kiran | last post by:
Hi, I have user control that I am using it for a Web Page. The User Control has a Dataset declared as class variable. When I call a function...
2
by: Andy G | last post by:
How can I check this for null? dsPrsn.Tables(0).Rows(0)("WORK_STATE") I tried If IsDbNull(dsPrsn.Tables(0).Rows(0)("WORK_STATE")) Then it seems...
0
by: Siegfried Heintze | last post by:
This program works fine on my desktop when I grant full control of the MSAccess database to everyone. However, when I put it on my hosting service...
6
by: DraguVaso | last post by:
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...
2
by: Anandan | last post by:
Hi, In our Project we use Dataset to load the Grid with Values. We have some criteria to filter the values to be shown in the Grid. For that...
6
by: marylipscomb | last post by:
I am using VB.NET. I am trying to connect a button so that when it is clicked the gridview pops up the data. Partial Class Switchboard ...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.