473,472 Members | 1,747 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Detecting Null Variables in an if statement c#

122 New Member
I want to know how you find out if a variable contains an null value in c#

I know for the string you have the string.isnullorempty

but what about integer etc... is there somewhere i can look to find all the possible functions to call for each datatype?
Oct 31 '07 #1
3 16403
r035198x
13,262 MVP
I want to know how you find out if a variable contains an null value in c#

I know for the string you have the string.isnullorempty

but what about integer etc... is there somewhere i can look to find all the possible functions to call for each datatype?
Expand|Select|Wrap|Line Numbers
  1. if(variable == null) {
  2. //
  3. }
Oct 31 '07 #2
DragonLord
122 New Member
Expand|Select|Wrap|Line Numbers
  1. if(variable == null) {
  2. //
  3. }
How about in C#?? I get an error if I do that saying that it can't ever be null as in the case of an integer, but if it is coming from a database that isn't always true..
Oct 31 '07 #3
nateraaaa
663 Recognized Expert Contributor
You will need to check for System.DBNull if you are checking to see if a database value is null in your C# code.

Expand|Select|Wrap|Line Numbers
  1. if(row["columnname"] != System.DBNull.Value)
  2. {
  3. //proceed
  4. }
  5. else
  6. {
  7. //value is null. Handle this.
  8. }
Nathan
Oct 31 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Chris | last post by:
I have tableA, defined as: field1 varchar2(10), field2 varchar2(10), field3 varchar2(10) I have host variables defined as: v1 pic x(10) varying v2 pic x(10) varying
1
by: dschmidt | last post by:
Does anybody know how to detect a NULL in a geometric box type? When I execute the following sql statement (coords is a box type) autotest=# select coords from dlg_control limit 1 autotest-# \g...
6
by: Rob | last post by:
int *p; p = malloc(1); free(p); /* */ In the above code, how do I detect that variable p points to nothing?
12
by: jyu.james | last post by:
I'm trying to detect reads of uninitialized global variables (that are declared in one file, and used in another as an extern). I know that ANSI C initializes all global variables to 0, however,...
9
by: D. Shane Fowlkes | last post by:
I'm using SQL Server 2000 and on my page, I'm simply creating a SQLDataReader and filling in Labels with the retrieved (single) record. However, how can I prevent from getting errors when a field...
5
by: corepaul | last post by:
I am using Acess 2000 and Windows 2000. I have a form with a text box txLName. tStrGlobal As String is dimensioned globally. The first time I enter the text box, the Enter event with the code ...
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...
1
by: gtwannabe | last post by:
I'm having a problem with a form that uses AutoNumber as the primary key. I have an Abort button to delete the current record and close the form. If AutoNumber is assigned, the code executes a...
8
by: A. Anderson | last post by:
Howdy everyone, I'm experiencing a problem with a program that I'm developing. Take a look at this stack report from GDB - #0 0xb7d782a3 in strlen () from /lib/tls/i686/cmov/libc.so.6 #1 ...
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.