I am having a problem with a DA class that I am writing. My problem seems to be stemming from when I try to put a date object into an Access database datetime field.
I believe it is a problem with my insert sql statement. Here it is.
My code compiles, but when I try to run it, I am getting an error when I try to run my TestSectionConnection class.Code:String sql = "INSERT INTO SECTIONS(course_number, section_number, instructor_id, days, start_time, end_time, begin_date, end_date, room_number) values(" + "'" + s.getCourseNum() + "'" + "," + s.getSectionNum() + "," + "'" + s.getInstrutorID()+"'" + "," + "'" + s.getDays() + "'" + "," + "#" + s.getBeginTime().getTime().getMonth() + "/" + s.getBeginTime().getTime().getDate() + "/" + s.getBeginTime().getTime().getYear()+ "#" + "," + "#" + s.getEndTime().getTime().getMonth() + "/" + s.getEndTime().getTime().getDate() + "/" + s.getEndTime().getTime().getYear()+ "#" + "," + "#" + s.getStartDate().getTime().getMonth() + "/" + s.getStartDate().getTime().getDate() + "/" + s.getStartDate().getTime().getYear()+ "#" + "," + "#" + s.getEndDate().getTime().getMonth() + "/" + s.getEndDate().getTime().getDate() + "/" + s.getEndDate().getTime().getYear()+ "#" + "," + "'" + s.getRoomNum() + "'" + ")";
I dont get where it is getting the date 11/31/-1898. It seems like it is getting bad data in part of the date object. Would not setting pieces of the date object when I put it into the database cause this error?Problems with query/update : [Microsoft][ODBC Microsoft Access Driver] Syntax error in date in query expression '#11/31/-1898#'.
Press any key to continue...
I have included my section da classes and my Access database in a zip file at the bottom of this post so you can look at it if you want to. I can post the code if you would rather read it here instead of getting it from the zip file. Any input is helpful. THanks




Reply With Quote