Solved

Date insert into MS SQL fails

Posted on 2013-01-17
6
238 Views
Last Modified: 2013-04-19
Hi

I get an error when ever I try to insert a date. The error is:

"Microsoft OLE DB Provider for SQL Server error '80040e07'

Conversion failed when converting date and/or time from character string."

Below is the code.


<%
        'Hele denne SQL og efterfølgende udføres hvis betalende medlemskab er valgt og betalt med dankort
        ok_fkIntUserID2 = rsUser("pkIntUserID")
        ok_strFName2 = rsUser("strFName")
        ok_strLName2 = rsUser("strLName")
        ok_strKlub2 = rsKlubProlong("strKlub")
        ok_fkIntSeasonID2 = Session("season")
        ok_fkIntItemID2 = Session("vare")
        ok_dmyApproveDate2 = date()
        ok_strApproved2 = 1
        ok_intAccessLevel2 = 2	
        
            Dim con2, sql2, data_source2
        
            data_source2 = "Provider=SQLOLEDB;Data Source=xxxxxxxx;Initial Catalog=xxxxxx;User ID=xxxxxx;Password=xxxxxxx"
            sql2 = "INSERT INTO dbo.tbl103TransactionsManual (fkIntUserID, strFName, strLName, strKlub, fkIntSeasonID, fkIntItemID, dmyApproveDate, strApproved, intAccessLevel) VALUES " & "('"& ok_fkIntUserID2 &"', '"& ok_strFName2 &"', '"& ok_strLName2 &"', '"& ok_strKlub2 &"', '"& ok_fkIntSeasonID2 &"', '"& ok_fkIntItemID2 &"', '"& ok_dmyApproveDate2 &"', '"& ok_strApproved2 &"', '"& ok_intAccessLevel2 &"')"
        
            ' Creating the Connection Object and opening the database
            Set con2 = Server.CreateObject("ADODB.Connection")
            con2.Open data_source2
        
            ' Executing the sql insertion code
            con2.Execute sql2
        
            ' Done. Now Close the connection
            con2.Close
            Set con2 = Nothing		'execute sql
        %>

Open in new window

0
Comment
Question by:jensjakobsen
  • 5
6 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 38789461
Do a Debug.Print sql2 so we can see the entire SQL statement.
0
 
LVL 1

Author Comment

by:jensjakobsen
ID: 38789471
And the MS SQL server is a 2012. EE didn't have that option.
0
 
LVL 1

Author Comment

by:jensjakobsen
ID: 38789472
How do I do a debug?
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 1

Author Comment

by:jensjakobsen
ID: 39077744
As this problem still is very relevant for me, I sincerely hope that someone will help me.

I have googled a LOT about the problem (and even how to do a debug), but it's still not that clear to me what I need to do to solve the problem.
0
 
LVL 1

Accepted Solution

by:
jensjakobsen earned 0 total points
ID: 39078145
Having found this link which works I suggest that this solution is accepted.

http://p2p.wrox.com/classic-asp-basics/32475-asp-sql-server-datetime-field.html
0
 
LVL 1

Author Closing Comment

by:jensjakobsen
ID: 39093782
Excellent solution, perfect for me.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql 2014,  lock limit 5 45
SQL Server 2008 R2 service pack updates 5 42
Parsing this XML works but the other one doesn't 9 27
SQL Select Query help 1 34
Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

713 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