Solved

VB.NET - Inserting Date to SQL Database formatting issue

Posted on 2010-08-18
4
337 Views
Last Modified: 2012-05-10
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?
0
Comment
Question by:holemania
  • 2
4 Comments
 
LVL 18

Expert Comment

by:Anil Golamari
ID: 33469221
0
 
LVL 35

Accepted Solution

by:
YZlat earned 500 total points
ID: 33469281
where is your code that does the insert?

According to your error, you are trying to insert string into datetime field in the database
0
 
LVL 35

Expert Comment

by:YZlat
ID: 33469306
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")
0
 

Author Closing Comment

by:holemania
ID: 33469561
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.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now