Problem inserting date into access table - VB 2005

mic_y

Expert Member
Joined
Dec 23, 2004
Messages
1,645
Hey guys,

Am having a small issue with inserting some data into a table...

Basically, I need to insert a date into a table. I am trying to do it as follows (some code omitted):

Code:
Dim DB_CMD As NewOleDB.OleDbCommand
Dim strDB_CMD
Dim ResStartDate As Date
Dim ResEndDate As Date

'Stuff to declare Connection, assign values to variables, etc...

strDM_CMD = "INSERT INTO Reservation (ReservationDate, StartDate, EndDate) VALUES 
                  (Convert.ToString(System.DateTime.Now.Date) 
                   & "," & Convert.ToString(ResStartDate)& "," & Convert.ToString(ResEndDate) & ")"

DB_CMD.CommandText = strDB_CMD

DB_CMD.ExecuteNonQuery

Now I have looked at the string that is generated (output it to a messagebox, and the problem is that when converting the date variables to string, the output is in the following format: DD\MM\YYYY 00:00:00.

Obviously, when passing this to the DB, the app crashes. Now, is there anything I can do to get rid of the time portion at the end of each Date?
 

mic_y

Expert Member
Joined
Dec 23, 2004
Messages
1,645
Awesome, thx dequadin :) the #'s worked perfectly :) had a couple other errors in the rest (fields mismatched and stuff, which was also not helping)... bleh, now to get this sorted, and hand in the damn project already...

bleh... why do they not teach us this stuff properly...
 

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,800
Format (and insert) your date: '14-Jun-2009' (example) and you will NEVER have a problem again. EVER
 
Top