DBNULL.Value Checking against each Column of a Result set

Here is the sample coding to do this.

Here,
dr means a DataRow of a DataTable.

// DBNULL.Value checking against each column value of a result set..



string strName = (dr["Name"] != DBNull.Value) ? dr["Name"].ToString()
: "";

string strAge = (dr["Age"] != DBNull.Value) ? dr["Age"].ToString()
: "";

string strSex = (dr["Sex"] != DBNull.Value) ? dr["Sex"].ToString() :
"";

No comments: