keerthimothukuri
asked on
Which should be used when comparing an object with null- Null or DBNull.Values
I have stored procedure which returns a table - dt. one of the columns in the table is a date column.
I need to write a condition wherein I need to check if the value is not equal to null
foreach (DataRow dr in dt.Rows)
{
// should I use dr[SendDate]!=null or dr [SendDate]!=DBnull.value. which is correct in this scenario? (senddate is a datetime type column)
if ((dr["SENDDATE"] != DBNull.Value)
{
}
}
Please let me know hich is correct to user dr[Sendate]!=null or dr[Sendate]!=DBnull.Value
I need to write a condition wherein I need to check if the value is not equal to null
foreach (DataRow dr in dt.Rows)
{
// should I use dr[SendDate]!=null or dr [SendDate]!=DBnull.value. which is correct in this scenario? (senddate is a datetime type column)
if ((dr["SENDDATE"] != DBNull.Value)
{
}
}
Please let me know hich is correct to user dr[Sendate]!=null or dr[Sendate]!=DBnull.Value
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The syntax I would use is this, as you loop through the results of the SqlDataReader returned by a call to ExecuteReader():
if (!reader.IsDBNull(reader.G
{
}
Some of that is my personal preference, but DBNull is definitely what you are trying to compare to.