Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 17, 2013 06:43 AM by davidofff
Member
119 Points
160 Posts
Feb 12, 2009 06:08 AM|LINK
Hi,
I am using the following code for checking dbnull
IIf(IsDBNull(dr("name")), "1",dr("name")))
in vb.net
what is alternative for this in C#?
thanks
Participant
1633 Points
1022 Posts
Feb 12, 2009 07:06 AM|LINK
You can check against the static value property of DBNull.
For example :
if(System.DbNull.Value(dr("name")), "1",dr("name"))
you can also check the Various code converters from vb.net to c#.
Sites like : http://www.carlosag.net/Tools/CodeTranslator
http://www.codechanger.com/
Hope this helps you.
Thank you
1730 Points
342 Posts
Feb 12, 2009 07:09 AM|LINK
For C#
DBNull
e.g.
if (! DBNull.Value.Equals(row[fieldName])) return (string) row[fieldName] + " ";
All-Star
78956 Points
13402 Posts
MVP
Feb 12, 2009 07:14 AM|LINK
try this
254 Points
50 Posts
Feb 12, 2009 07:21 AM|LINK
hi,
You can use below any of one to check the null value.
{
}
or
vinay
15176 Points
3304 Posts
Feb 12, 2009 07:56 AM|LINK
use DBNull.Value to check the row value..
1538 Points
310 Posts
Feb 12, 2009 08:09 AM|LINK
if(dr("name")==System.DBNull.Value)
844 Points
148 Posts
Feb 12, 2009 08:52 AM|LINK
60 Points
45 Posts
Sep 26, 2012 05:43 AM|LINK
Thanks. It helped me....
10 Points
5 Posts
Apr 17, 2013 06:43 AM|LINK
Use like this
if (ds.Tables[0].Rows[i].ItemArray[0] == System.DBNull.Value) {
MessageBox.Show("DBNULL exist in the field ");
else
MessageBox.Show(ds.Tables[0].Rows[i][0].ToString());
full source : http://net-informations.com/csprj/ado.net/cs-dbnull.htm
gever
sangeeta chh...
Member
119 Points
160 Posts
How to check dbnull in C#
Feb 12, 2009 06:08 AM|LINK
Hi,
I am using the following code for checking dbnull
IIf(IsDBNull(dr("name")), "1",dr("name")))
in vb.net
what is alternative for this in C#?
thanks
venkatzeus
Participant
1633 Points
1022 Posts
Re: How to check dbnull in C#
Feb 12, 2009 07:06 AM|LINK
Hi,
You can check against the static value property of DBNull.
For example :
if(System.DbNull.Value(dr("name")), "1",dr("name"))you can also check the Various code converters from vb.net to c#.
Sites like : http://www.carlosag.net/Tools/CodeTranslator
http://www.codechanger.com/
Hope this helps you.
Thank you
worldclassco...
Participant
1730 Points
342 Posts
Re: How to check dbnull in C#
Feb 12, 2009 07:09 AM|LINK
For C#
DBNull
.Value(YourVariable/FieldName)e.g.
if (! DBNull.Value.Equals(row[fieldName]))
return (string) row[fieldName] + " ";
Robin Kedia
www.robinkedia.com
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: How to check dbnull in C#
Feb 12, 2009 07:14 AM|LINK
try this
string name = dr["name"] == DBNull.Value ? "1" : dr["name"].ToString();Contact me
vinayget
Member
254 Points
50 Posts
Re: How to check dbnull in C#
Feb 12, 2009 07:21 AM|LINK
hi,
You can use below any of one to check the null value.
if (string.IsNullOrEmpty(Convert.ToString(Dr["Name"]))){
}
or
if (System.DBNull.Value == Dr["Name"]){
}
vinay
.net Sr. Developer
Hyderabad
suthish nair
All-Star
15176 Points
3304 Posts
Re: How to check dbnull in C#
Feb 12, 2009 07:56 AM|LINK
use DBNull.Value to check the row value..
My Blog
gayathri.pms...
Participant
1538 Points
310 Posts
Re: How to check dbnull in C#
Feb 12, 2009 08:09 AM|LINK
if(dr("name")==System.DBNull.Value)
{
}
Gayathri
dreamz
Participant
844 Points
148 Posts
Re: How to check dbnull in C#
Feb 12, 2009 08:52 AM|LINK
cmayil
Member
60 Points
45 Posts
Re: How to check dbnull in C#
Sep 26, 2012 05:43 AM|LINK
Thanks. It helped me....
davidofff
Member
10 Points
5 Posts
Re: How to check dbnull in C#
Apr 17, 2013 06:43 AM|LINK
Use like this
if (ds.Tables[0].Rows[i].ItemArray[0] == System.DBNull.Value) {
MessageBox.Show("DBNULL exist in the field ");
}
else
{
MessageBox.Show(ds.Tables[0].Rows[i][0].ToString());
}
full source : http://net-informations.com/csprj/ado.net/cs-dbnull.htm
gever