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

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

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
 
If IsDBNull(view[0].Row["DeliveryAddress"]) then

Else

End if

or...

if view[0].Row["DeliveryAddress"] = DBNull.value then....
 
Thanks Scott
Regards
Mark
Scott M. said:
If IsDBNull(view[0].Row["DeliveryAddress"]) then

Else

End if

or...

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

Mark said:
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
 
Back
Top