Tuesday, March 13, 2012

Set property for datetime field

How do I set the property for a datetime field? The get works (compiles; don't know yet if it works) with .ToString(). The set doesn't compile with just "= value".

public string CreateDate
{get{return issuesCurrentRow.CreateDate.ToString();}
set{issuesCurrentRow.CreateDate = value;}}

And I assume that datetimes are handled as strings??

I've been looking through my books and online; haven't found any info yet. I'm sure it's a simple answer...

Thanks,
Sherilyn

set{issuesCurrentRow.CreateDate = DateTime.Now;}}

will compile. And I do want to use the current date/time on the system. My "set" value is going into the database, so this seems right.

I'd like to hear any objections. Thanks.
It is because you are assigning string value to a datetime data type.

Try this...

public DateTime CreateDate
{
get
{
return issuesCurrentRow.CreateDate;
}
set
{
issuesCurrentRow.CreateDate = value;
}

}

and change the value to string when you call the property.

Thanks,
Sridhar!!

0 comments:

Post a Comment