holemania
asked on
VB.NET - Inserting Date to SQL Database formatting issue
I created a windows form application that will insert data into a SQL Server 2005 database. When I do this, I get the following error.
Conversion failed when converting datetime from character string.
Here's my VB.Code:
Dim strDate as STring = Format(Cdate(DateTime.Now) , "yyyy-MM-dd").ToString
The date in the database should look like the following: 2010-08-18 00:00:00.000
Trying to get it to same format for the insert. Any ideas?
Conversion failed when converting datetime from character string.
Here's my VB.Code:
Dim strDate as STring = Format(Cdate(DateTime.Now)
The date in the database should look like the following: 2010-08-18 00:00:00.000
Trying to get it to same format for the insert. Any ideas?
http://redsouljaz.com/2010/01/15/vb-net-date-time-format-patterns/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try replacing
Dim strDate as STring = Format(Cdate(DateTime.Now) , "yyyy-MM-dd").ToString
with
Dim strDate as STring = DateTime.Now.ToString("yyy y-MM-dd")
Dim strDate as STring = Format(Cdate(DateTime.Now)
with
Dim strDate as STring = DateTime.Now.ToString("yyy
ASKER
Thanks. You are right, I was inserting it into the wrong field. Too many of them so I got less fields in my insert then my values.