Click here to Skip to main content
15,886,864 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
What is the differece between IsDBNull and IsNull?
Posted

In database like Sql Server NULL represents a non existant value. Whereas null in C# represents if an object reference is not set.

ISNULL is Sql Server function as explained here http://msdn.microsoft.com/en-us/library/ms184325.aspx[^] and checks for this non existent value.

In C# the non existent value cannot be compared to null. Hence, a class DBNull is provided in .NET as explained here http://msdn.microsoft.com/en-us/library/system.dbnull.aspx[^]

The IsDBNull is the method of this DBNull class as explained here
http://msdn.microsoft.com/en-us/library/tckcces5(v=vs.71).aspx[^]
to test whether the data is non existent or missing.
 
Share this answer
 
Comments
Prasad_Kulkarni 22-May-12 3:36am    
Good one +5!
VJ Reddy 22-May-12 3:44am    
Thank you, Prasad :)
Wendelius 22-May-12 16:30pm    
Good answer
VJ Reddy 22-May-12 20:14pm    
Thank you, Mika :)
Mohamed Mitwalli 23-May-12 9:41am    
5+
The IsDBNull method tests whether the value parameter is equal to DBNull.Value & returns an indication whether the specified object is of type DBNull.

The System.DBNull value indicates that the Object represents missing or nonexistent data.
DBNull is not the same as Nothing, which indicates that a variable has not yet been initialized.
DBNull is also not the same as a zero-length string (""), which is sometimes referred to as a null string.

DBNull returns True if the data type of Expression evaluates to the DBNull type; otherwise, IsDBNull returns False.

IsNull
Replaces NULL with the specified replacement value.
Please refer: ISNULL (Transact-SQL)[^]

Additional info:
Learn the differences between Is Null and IsNull()[^]
 
Share this answer
 
Comments
Wendelius 22-May-12 16:30pm    
Also a good answer
Prasad_Kulkarni 23-May-12 0:04am    
Thank you Mika!
If object is null, then it has no value, on the other hand DBNull is value.
 
Share this answer
 
the object which is declared but not initialized is null
and
the value retirves from database is null is called DBNull
Null value of database is always DBNull not null

C#
int ob;
DataSet ds ;
DataTable tbl;

the value of above object is null

but
the value in database is null here retrive DBNull of below statement

C#
ds.Tables[0].Rows[0][0] 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900