Solved

VB.NET - Inserting Date to SQL Database formatting issue

Posted on 2010-08-18
4
336 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Populating an array of locale_time_info 8 37
Opening and Closing Connections and Data Adapters 10 42
LINQ - C# to VB convertion 12 46
Get Top Visible Row of Datagridview 6 27
As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

911 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

18 Experts available now in Live!

Get 1:1 Help Now