473,419 Members | 1,635 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 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 7429
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 contain value null. If someone is reading this value...
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 the data null value how can i pass this null...
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 location of the value within the ListItem...
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 of that User Control from Web page, I am...
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 not too work. I am attempting to check this field...
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 with no impersonation, I now get this error (see...
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 is DBNull". But aren't Typed DataSets...
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 we used the SELECT command to filter the Same...
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 Inherits System.Web.UI.Page Protected Sub...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.