Format date problem

daisy25
02-14-2005, 10:08 AM
Hi all, when executing this code:
Dim saleCommand As New SqlCommand("INSERT INTO SalesDetails ([Date], [Time], [OperatorID], [CustomerID], [PaymentID]) VALUES ('" & Format(Now(), "dd/MM/yyyy") & "', '" & Format(Now(), "HH:mm") & "', '1', '1', '1');", myConnection)

I get a data type conversion error saying the conversion from string to datetime caused an out-of-range data value. But when I execute this code:
Dim saleCommand As New SqlCommand("INSERT INTO SalesDetails ([Date], [Time], [OperatorID], [CustomerID], [PaymentID]) VALUES ("#& Format(Now(), "dd/MM/yyyy") & "#, #" & Format(Now(), "HH:mm") & "#, '1', '1', '1');", myConnection)
I get an error saying "The name '#14' is not permitted in this context".
Any ideas?

daisy25
02-14-2005, 02:58 PM
I got it sorted, the way I was formatting the date, it was being taken into SQL Server as the month being 14 , god knows why. So I just changed the format and executed:
Dim saleCommand As New SqlCommand("INSERT INTO SalesDetails ([Date], [Time], [OperatorID], [CustomerID], [PaymentID]) VALUES ('" & Format(Now, "MM/dd/yyyy") & "', '" & Format(Now, "HH:mm") & "', '1', '1', '1');", myConnection)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum