-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: laks_win
Message 6 in Discussion
Hi Guys
[Quote]
From: commander4u
DBNULL
represents NULL values in the Database column. If a column
value in
Database is NULL it can't be represented as NULL in C# or
VB.NET, we
have to represent it as DBNULL value
[Quote]
Yes, commander4u
is correct!
Eventhough, a little bit
comparion having is
<o:p> </o:p>
Null
DBNull
1
Default value of reference
type variable
Default value for any type
of �un initialized � field
from database table
2
Represents, NULL with C#
environment for the reference type members<o:p></o:p>
In Database application,
records having 'un initialized' fields/column are represented as �DBNull�
with C# environment<o:p></o:p>
3
<o:p> </o:p>
Singleton class, the values
is available with �DBNull.Value�.
With sealed class and
static field.
[class]
//
from module
'c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll'
public
sealed class DBNull
:
object,
System.Runtime.Serialization.ISerializable,
IConvertible
{
//
Fields
public static readonly DBNull
Value;
���������..<o:p></o:p>
}
//
4
Used with reference type
only [Value types are not nullable]
May check/use it with any
type of data from table field
5
Instance members are not
thread-safe
Being non-instance (sealed
with static field), guaranteed to thread-safe
6
Can be used in
assignment
Cannot
<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>
Try
this,<o:p></o:p>
<o:p> </o:p>
SqlConnection objCon =
new SqlConnection(strCon);<o:p></o:p>
SqlCommand objCom =
new SqlCommand("select top 1
deptno from dept order by id desc", objCon);<o:p></o:p>
<o:p> </o:p>
objCon.Open();<o:p></o:p>
<o:p></o:p>
object Res =
objCom.ExecuteScalar();<o:p></o:p>
MessageBox.Show("Type = " + Res.GetType());<o:p></o:p>
<o:p> </o:p>
//this
will display �Type = System.DBNull�, if the �deptno� from the query comes with
null. Otherwise, will display the datatype coming.
Hope,
this helps all.
Regards
Lakshmi
Narayanan.R<o:p></o:p>
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you
received this message by mistake, please click the "Remove" link below. On the
pre-addressed e-mail message that opens, simply click "Send". Your e-mail
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]