472,791 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,791 software developers and data experts.

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 7051
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
1
by: Luis | last post by:
Is there an easier way to check if any of the fields returned in a select statement have null values? After running this command: set rs = conn.execute("select A,B,C,D,E,F,G,H,I,J from...
4
by: Chuck Ritzke | last post by:
I keep asking myself this question as I write class modules. What's the best/smartest/most efficient way to send a large object back and forth to a class module? For example, say I have a data...
2
by: Pekka Henttonen | last post by:
Forgive me this stupid question, but what is the best way to store the length of an object in a database? What datatype would you use? Would it be better to define one of your own?
6
by: AAVF | last post by:
Hi We have a problem with a query. An Access database links via ODBC to a UNIX server. To speed things, we use the ODBC to load the relevant tables to the local PC that runs Access so that...
0
by: Anonieko Ramos | last post by:
ASP.NET Forms Authentication Best Practices Dr. Dobb's Journal February 2004 Protecting user information is critical By Douglas Reilly Douglas is the author of Designing Microsoft ASP.NET...
2
by: Mark | last post by:
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...
17
by: Mark A | last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP 11). Using the SAMPLE database, tables EMP and EMLOYEE. In the followng stored procedure, 2 NULL columns (COMM) are...
2
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.