Link to home
Start Free TrialLog in
Avatar of holemania
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?
Avatar of Anil Golamari
Anil Golamari
Flag of United States of America image

ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try replacing

Dim strDate as STring = Format(Cdate(DateTime.Now), "yyyy-MM-dd").ToString

with

Dim strDate as STring = DateTime.Now.ToString("yyyy-MM-dd")
Avatar of holemania
holemania

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.