473,378 Members | 1,555 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,378 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
Nov 21 '05 #1
6 5030
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

Nov 21 '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


Nov 21 '05 #3
DraguVaso schrieb:
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..
You don't need try-catch becaue you can call
mytable.row(index).IsFieldnameNull
before.

Which sense would make a *typed* dataset if it was not typed? As an Integer
field is still not always Integer, the field/property type is Integer *and*
there is a IsFieldNameNull and SetFieldNameNull method. If the
property/field type was Object, you wouldn't know the field type and you
would have to do casting on your own.

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


You have to handle Null values as special values in your application anyway,
so I don't see a problem.

Armin
Nov 21 '05 #4
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

Nov 21 '05 #5
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


Nov 21 '05 #6
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?
Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
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...
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...
12
by: Jose Fernandez | last post by:
Hello. I'm building a web service and I get this error. NEWS.News.CoverNews(string)': not all code paths return a value This is the WebMethod public SqlDataReader CoverNews(string Sport)...
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...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.