Sunday, 9 November 2014

check dbnull in c# and VB.Net


Check dbnull in C# as per Bellow.

String Example
string name = dr["name"] == DBNull.Value ? "1" : dr["name"].ToString(); 

Integer example
int name = dr["name"] == DBNull.Value ? "1" : dr["name"].ToString();  



You can also Check Like Bellow
if (string.IsNullOrEmpty(Convert.ToString(Dr["Name"]))) {
}
or
if (System.DBNull.Value == Dr["Name"]) {
} .


 Check dbnull in VB.Net as per Bellow.

IIf(IsDBNull(dr("name")), "1",dr("name"))) 

No comments:

Post a Comment

AngularJs6 using with Asp.net Core Web API 2

AngularJs6 using with Asp.net Core Web API 2 Steps 1) Create project using with command 2) Create services 3) Create routing 4) Modif...