|
-
August 28th, 2008, 11:06 AM
#1
How do I insert a DateTime.Now into SQL
Hi There,
I am tearing my hair out. I cannot see how to insert a date into SQL server.
I have a datetime field in an SQL database.
I want to store a .NET DateTime type into the SQL field.
I have tried:
string dateTimeNow = DateTime.Now.ToString();
testTimeStop = SqlDateTime.Parse(dateTimeNow);
and because I thought it might need the SQL format.
string dateTimeNow = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff");
testTimeStop = SqlDateTime.Parse(dateTimeNow);
In both cases I get an error:
"String was not recognized as a valid DateTime."
I have also tried a vast panoply of other ideas from the web. None of which have panned out.
I can't just store it as a varchar ( although I would like to!)
Any ideas / suggestions?
Thanks in advance
Richard
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|