Solved

VB.NET - Inserting Date to SQL Database formatting issue

Posted on 2010-08-18
4
341 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

695 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