Reputation: 5738
Continuation with the earlier post: How to check object is null or empty in C#.NET 3.5?
In my code i handled successfully if the object is null
BUT
I'm not getting How to check the DataRow object dtTable.Rows[0][4]
is Empty or NOT
dblRevenue = Convert.ToDouble(dtTable.Rows[0][4]);
Please help!!
Upvotes: 1
Views: 621
Reputation: 62
Try this solution. You can easily convert value without any exception.
long lValue = 0;
long.TryParse(dtTable.Rows[0][4], out lValue);
Upvotes: 0
Reputation: 11
if (dtTable.Rows[0][4] != null && dtTable.Rows[0][4] != DBNull.Value)
{
dblRevenue = Convert.ToDouble(dtTable.Rows[0][4]);
...
}
else
{
dblRevenue = 0.0;
}
May be it is so Bloated .
Upvotes: 1
Reputation: 1
You have to check, if the value of the cell is typed as System.DBNull. If it is, you cannot convert it to double without getting an exception on type conversion.
You do know that you can evaluate the type of a given item within the IDE?
Upvotes: 0
Reputation: 55248
Try this.
dblRevenue = dtTable.Rows[0][4] == DBNull.Value ? 0.00 : Convert.ToDouble(dtTable.Rows[0][4]);
Upvotes: 5