I have a column with the date
type in my SQL database. How can I convert it to C# DateTime
and then back again to a SQL date
?
I have a column with the date
type in my SQL database. How can I convert it to C# DateTime
and then back again to a SQL date
?
A sql DATE
can be directly cast to a .net DateTime
and vice-versa.
to get it, use the SqlDataReader.GetDatetime Method
DateTime myDate = myDataReader.GetDateTime(myColumnIndex);
to set it, simply assign it to the value of the SqlParameter and use the .Date
property of the DateTime