469,332 Members | 6,807 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,332 developers. It's quick & easy.

Best way to check for a null value returned from a database?

Hi, If I have a DataView containing some items and what I want to do is
restore a textbox with an item in one of the rows.

If the item in the datarow is null then obviously I get an error when I try
to bind the item to the textbox
e.g.

uiDelivery.Text = view[0].Row["DeliveryAddress"].ToString();

My question is, what is the best way to test for a null value in C#??

I have seen everything from try catch statements to !=String.Empty() and
==null

Thanks in advance
Mark
Jul 22 '05 #1
2 6938
If IsDBNull(view[0].Row["DeliveryAddress"]) then

Else

End if

or...

if view[0].Row["DeliveryAddress"] = DBNull.value then....

"Mark" <do**@spam.me> wrote in message
news:Ov**************@tk2msftngp13.phx.gbl...
Hi, If I have a DataView containing some items and what I want to do is
restore a textbox with an item in one of the rows.

If the item in the datarow is null then obviously I get an error when I
try
to bind the item to the textbox
e.g.

uiDelivery.Text = view[0].Row["DeliveryAddress"].ToString();

My question is, what is the best way to test for a null value in C#??

I have seen everything from try catch statements to !=String.Empty() and
==null

Thanks in advance
Mark

Jul 22 '05 #2
Thanks Scott
Regards
Mark
"Scott M." <s-***@nospam.nospam> wrote in message
news:O4****************@TK2MSFTNGP14.phx.gbl...
If IsDBNull(view[0].Row["DeliveryAddress"]) then

Else

End if

or...

if view[0].Row["DeliveryAddress"] = DBNull.value then....

"Mark" <do**@spam.me> wrote in message
news:Ov**************@tk2msftngp13.phx.gbl...
Hi, If I have a DataView containing some items and what I want to do is
restore a textbox with an item in one of the rows.

If the item in the datarow is null then obviously I get an error when I
try
to bind the item to the textbox
e.g.

uiDelivery.Text = view[0].Row["DeliveryAddress"].ToString();

My question is, what is the best way to test for a null value in C#??

I have seen everything from try catch statements to !=String.Empty() and
==null

Thanks in advance
Mark


Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Luis | last post: by
reply views Thread by Anonieko Ramos | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by haryvincent176 | last post: by
reply views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.