Reputation: 495
I am using .net 4.0. I have interface with date time fields like
DateTime FromDate
{
get;
set;
}
DateTime ToDate
{
get;
set;
}
I want to set the value to this to null in my user interface like
IUser m_user = new User();
m_user.FromDate = DBNull.value;
In shows error , like cannot convert null to datetime.
How to assign null to datetime?
Thanks , pooja
Upvotes: 1
Views: 2094
Reputation: 66388
You can't do that, as DateTime can't get null
value because it's value type.
One way is changing your code to use Nullable type instead:
DateTime? FromDate
{
get;
set;
}
Then it can be null:
m_user.FromDate = null;
Upvotes: 10