473,396 Members | 1,726 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,396 software developers and data experts.

Null value

I AM A NEWBIE. ANy help appreciated

The following statement crashes when the database entry is dbNUll How
do I prevent it

Name = ds.Tables(0).Rows.Item(i).ItemArray.GetValue(1)
May 21 '07 #1
8 3082
Never mind dound isdbnull
May 21 '07 #2
On 21 May, 14:41, J...@gmail.com wrote:
I AM A NEWBIE. ANy help appreciated

The following statement crashes when the database entry is dbNUll How
do I prevent it

Name = ds.Tables(0).Rows.Item(i).ItemArray.GetValue(1)
Hi

you can use these two methods..

Name =
ds.Tables(0).Rows.Item(i).ItemArray.GetValue(1).To string()

or

if
isDBNull(ds.Tables(0).Rows.Item(i).ItemArray.GetVa lue(1))=false then

Name =
ds.Tables(0).Rows.Item(i).ItemArray.GetValue(1).To string()

end if
May 21 '07 #3
Maybe:

If x Is Nothing then
Beep()
Else
t = x
end if
"Je**@gmail.com" wrote:
I AM A NEWBIE. ANy help appreciated

The following statement crashes when the database entry is dbNUll How
do I prevent it

Name = ds.Tables(0).Rows.Item(i).ItemArray.GetValue(1)
May 22 '07 #4
On May 21, 7:41 pm, J...@gmail.com wrote:
I AM A NEWBIE. ANy help appreciated

The following statement crashes when the database entry is dbNUll How
do I prevent it

Name = ds.Tables(0).Rows.Item(i).ItemArray.GetValue(1)
What I find that works is
if ds.Tables(0).Rows.Item(i).ItemArray.GetValue(1) = "" then
Name = "Empty"
Else
Name = ds.Tables(0).Rows.Item(i).ItemArray.GetValue(1)
End if

What is wierd in .net 2.0 i sthat isdbnull or isnull don;t work as
well!
If someone can elaborate....

Tom Bizannes
Sydney,Australia

May 22 '07 #5
First of all, a little pointer because you are making life difficult for
yourself.

The Item property of the Rows collection of a DataTable is the default
property so you don't have to code:

ds.Tables(0).Rows.Item(i)

Rather, you can simply code:

ds.Tables(0).Rows(i)

Similarly, the default property of a DataRow is DataColumns (or Columns) and
the default property of a DataColumn (or Column) is Value. Therefore it is
simpler to code:

Name = ds.Tables(0).Rows(i)(1)

Assuming Name is a String, then because the Value property returns an Object
you will need to cast it accordingly:

Name = CType(ds.Tables(0).Rows(i)(1), String)

Now this is where DbNull's rear their ugly head because you can't cast a
DbNull to a String (or any other type for that matter.

What you have to do is determine your business rule for handling DbNull.
If, for instance, you decide that (for a String) dbNull should beconverted
to an empty string then you can use:

Name = String.Empty

If Not IsDbNull(ds.Tables(0).Rows(i)(1)) Then Name =
CType(ds.Tables(0).Rows(i)(1), String)

As a variation you couild could also use:

If ds.Tables(0).Rows(i)(1) <DbNull.Value Then Name =
CType(ds.Tables(0).Rows(i)(1), String)

That is really a matter of personal preference but whichever you use it must
fit in your comfort zone.

For Tom, the IsDbNull certainly does work in Framework 2.0 but the IsNull
function will certainly NOT work in relation to DbNull's.

The secret is to make sure you learn the difference between DbNull.Value and
Nothing which are completely different things.
"SmartbizAustralia" <to*@smartbiz.com.auwrote in message
news:11**********************@x35g2000prf.googlegr oups.com...
On May 21, 7:41 pm, J...@gmail.com wrote:
>I AM A NEWBIE. ANy help appreciated

The following statement crashes when the database entry is dbNUll How
do I prevent it

Name = ds.Tables(0).Rows.Item(i).ItemArray.GetValue(1)

What I find that works is
if ds.Tables(0).Rows.Item(i).ItemArray.GetValue(1) = "" then
Name = "Empty"
Else
Name = ds.Tables(0).Rows.Item(i).ItemArray.GetValue(1)
End if

What is wierd in .net 2.0 i sthat isdbnull or isnull don;t work as
well!
If someone can elaborate....

Tom Bizannes
Sydney,Australia
May 22 '07 #6
>
The secret is to make sure you learn the difference between DbNull.Value
and Nothing which are completely different things.
A DbNull.Value means a not with a 'value' filled column in a database or any
other data collection that expects a value.
Nothing means a not with a 'reference' filled address in your program.

Cor
>
"SmartbizAustralia" <to*@smartbiz.com.auwrote in message
news:11**********************@x35g2000prf.googlegr oups.com...
>On May 21, 7:41 pm, J...@gmail.com wrote:
>>I AM A NEWBIE. ANy help appreciated

The following statement crashes when the database entry is dbNUll How
do I prevent it

Name = ds.Tables(0).Rows.Item(i).ItemArray.GetValue(1)

What I find that works is
if ds.Tables(0).Rows.Item(i).ItemArray.GetValue(1) = "" then
Name = "Empty"
Else
Name = ds.Tables(0).Rows.Item(i).ItemArray.GetValue(1)
End if

What is wierd in .net 2.0 i sthat isdbnull or isnull don;t work as
well!
If someone can elaborate....

Tom Bizannes
Sydney,Australia

May 22 '07 #7
Hi Stephany,

Just a little question, why don't you use the most base method ToString here
or even the VB function Cstr.
The result will be the same however it is less typing.

Cor

"Stephany Young" <noone@localhostschreef in bericht
news:ei**************@TK2MSFTNGP06.phx.gbl...
First of all, a little pointer because you are making life difficult for
yourself.

The Item property of the Rows collection of a DataTable is the default
property so you don't have to code:

ds.Tables(0).Rows.Item(i)

Rather, you can simply code:

ds.Tables(0).Rows(i)

Similarly, the default property of a DataRow is DataColumns (or Columns)
and the default property of a DataColumn (or Column) is Value. Therefore
it is simpler to code:

Name = ds.Tables(0).Rows(i)(1)

Assuming Name is a String, then because the Value property returns an
Object you will need to cast it accordingly:

Name = CType(ds.Tables(0).Rows(i)(1), String)

Now this is where DbNull's rear their ugly head because you can't cast a
DbNull to a String (or any other type for that matter.

What you have to do is determine your business rule for handling DbNull.
If, for instance, you decide that (for a String) dbNull should beconverted
to an empty string then you can use:

Name = String.Empty

If Not IsDbNull(ds.Tables(0).Rows(i)(1)) Then Name =
CType(ds.Tables(0).Rows(i)(1), String)

As a variation you couild could also use:

If ds.Tables(0).Rows(i)(1) <DbNull.Value Then Name =
CType(ds.Tables(0).Rows(i)(1), String)

That is really a matter of personal preference but whichever you use it
must fit in your comfort zone.

For Tom, the IsDbNull certainly does work in Framework 2.0 but the IsNull
function will certainly NOT work in relation to DbNull's.

The secret is to make sure you learn the difference between DbNull.Value
and Nothing which are completely different things.
"SmartbizAustralia" <to*@smartbiz.com.auwrote in message
news:11**********************@x35g2000prf.googlegr oups.com...
>On May 21, 7:41 pm, J...@gmail.com wrote:
>>I AM A NEWBIE. ANy help appreciated

The following statement crashes when the database entry is dbNUll How
do I prevent it

Name = ds.Tables(0).Rows.Item(i).ItemArray.GetValue(1)

What I find that works is
if ds.Tables(0).Rows.Item(i).ItemArray.GetValue(1) = "" then
Name = "Empty"
Else
Name = ds.Tables(0).Rows.Item(i).ItemArray.GetValue(1)
End if

What is wierd in .net 2.0 i sthat isdbnull or isnull don;t work as
well!
If someone can elaborate....

Tom Bizannes
Sydney,Australia

May 22 '07 #8
Personal preference.

If saving a few keystrokes here and there was my biggest issue then I would
be very happy indeed.
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:u6**************@TK2MSFTNGP04.phx.gbl...
Hi Stephany,

Just a little question, why don't you use the most base method ToString
here or even the VB function Cstr.
The result will be the same however it is less typing.

Cor

"Stephany Young" <noone@localhostschreef in bericht
news:ei**************@TK2MSFTNGP06.phx.gbl...
>First of all, a little pointer because you are making life difficult for
yourself.

The Item property of the Rows collection of a DataTable is the default
property so you don't have to code:

ds.Tables(0).Rows.Item(i)

Rather, you can simply code:

ds.Tables(0).Rows(i)

Similarly, the default property of a DataRow is DataColumns (or Columns)
and the default property of a DataColumn (or Column) is Value. Therefore
it is simpler to code:

Name = ds.Tables(0).Rows(i)(1)

Assuming Name is a String, then because the Value property returns an
Object you will need to cast it accordingly:

Name = CType(ds.Tables(0).Rows(i)(1), String)

Now this is where DbNull's rear their ugly head because you can't cast a
DbNull to a String (or any other type for that matter.

What you have to do is determine your business rule for handling DbNull.
If, for instance, you decide that (for a String) dbNull should
beconverted to an empty string then you can use:

Name = String.Empty

If Not IsDbNull(ds.Tables(0).Rows(i)(1)) Then Name =
CType(ds.Tables(0).Rows(i)(1), String)

As a variation you couild could also use:

If ds.Tables(0).Rows(i)(1) <DbNull.Value Then Name =
CType(ds.Tables(0).Rows(i)(1), String)

That is really a matter of personal preference but whichever you use it
must fit in your comfort zone.

For Tom, the IsDbNull certainly does work in Framework 2.0 but the IsNull
function will certainly NOT work in relation to DbNull's.

The secret is to make sure you learn the difference between DbNull.Value
and Nothing which are completely different things.
"SmartbizAustralia" <to*@smartbiz.com.auwrote in message
news:11**********************@x35g2000prf.googleg roups.com...
>>On May 21, 7:41 pm, J...@gmail.com wrote:
I AM A NEWBIE. ANy help appreciated

The following statement crashes when the database entry is dbNUll How
do I prevent it

Name = ds.Tables(0).Rows.Item(i).ItemArray.GetValue(1)

What I find that works is
if ds.Tables(0).Rows.Item(i).ItemArray.GetValue(1) = "" then
Name = "Empty"
Else
Name = ds.Tables(0).Rows.Item(i).ItemArray.GetValue(1)
End if

What is wierd in .net 2.0 i sthat isdbnull or isnull don;t work as
well!
If someone can elaborate....

Tom Bizannes
Sydney,Australia

May 22 '07 #9

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

Similar topics

3
by: iStrain | last post by:
Hiya. I'm _sure_ this is an FAQ, but Googling hasn't produced the answer in a way I can make sense out of. I know I should get this, but so far no way... I'm creating tables and doing queries in...
102
by: junky_fellow | last post by:
Can 0x0 be a valid virtual address in the address space of an application ? If it is valid, then the location pointed by a NULL pointer is also valid and application should not receive "SIGSEGV"...
99
by: Mikhail Teterin | last post by:
Hello! Consider the following simple accessor function: typedef struct { int i; char name; } MY_TYPE; const char *
64
by: yossi.kreinin | last post by:
Hi! There is a system where 0x0 is a valid address, but 0xffffffff isn't. How can null pointers be treated by a compiler (besides the typical "solution" of still using 0x0 for "null")? -...
3
ADezii
by: ADezii | last post by:
Null as it relates to database development is one of life's little mysteries and a topic of total confusion for novices who venture out into the database world. A Null Value is not zero (0), a zero...
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.