Solved

VB.NET - Inserting Date to SQL Database formatting issue

Posted on 2010-08-18
4
335 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
Comment Utility
0
 
LVL 35

Accepted Solution

by:
YZlat earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

'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 …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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