Hello,
I am creating a web server which lets me insert into a table. The user invokes the specific ID and its meant to append to the table with that ID, startdate and an enddate.
<WebMethod()> _
Public Function reserveVehicle1(ByVal vID As Integer) As Boolean
Dim strInsert As String
Dim conn As SqlConnection
Dim cmd As SqlCommand
Dim now As DateTime = System.DateTime.Now
Dim now5 As DateTime = System.DateTime.Now.AddMinutes(5)
Dim connString As String
connString = "server=xxxx"
strInsert = String.Format("Insert into Reservation (VehicleID, startDate, enddate) VALUES ('{0}','{1}','{2}')", vID, now, now5)
It was working perfectly up til today until an error came up whilst attemping it:
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
Upon looking at the Reservation table, it seems that its appending it with the DD and the MM the opposite way around.
For example, the last time I appended it (when it worked) was two days ago (11th of December). Here are the last several rows with the information:
20 2 12/08/2011 19:27:14 12/08/2011 19:32:14
22 2 12/08/2011 19:28:29 12/08/2011 19:33:29
24 1 12/08/2011 19:28:37 12/08/2011 19:33:37
25 1 12/08/2011 19:28:38 12/08/2011 19:33:38
26 3 12/11/2011 16:45:13 12/11/2011 16:50:13
27 3 12/11/2011 16:48:42 12/11/2011 16:53:42
The first two columns are BookingID and VehicleID. Its saying that its gone from August (8) to November (11) in 3 days. Its now not working because its a DD in the month higher than 12 so its screwing up.
So I am putting it to you guys on how I can fix this problem. I created a simple .aspx page with a label showing system.datetime.now and it was showing the correct datetime (13/12/2011 19:52:08) as of now.
Cheers.