PDA

View Full Version : Insert QDate into MS Access DB



mabeeh
16th December 2008, 19:18
I'm trying to insert a date stamp into a MS Access DB column that is of type Date/Time. I can insert all the other values (which are text fields) fine. But when I attempt to add the field for Date the query doesn't work. Please help. Thanks!



QSqlQuery query;
QDateTime currDate = QDateTime::currentDateTime();

query.prepare("INSERT INTO DwgHistory (historyDate, historyDwgNumber, historyDwgTitle, historyDwgEngineer, historyDwgDateToCad, historyDwgDateRequired, historyDwgDateReturnedFromCad, historyDwgDraftsman, historyDwgSource, historyDwgApprovedDate, historyDwgReleaseDate, historyDwgStatus, historyDwgPrecedence, historyDwgComments) "
"VALUES (:historyDate, :historyDwgNumber, :historyDwgTitle, :historyDwgEngineer, :historyDwgDateToCad, :historyDwgDateRequired, :historyDwgDateReturnedFromCad, :historyDwgDraftsman, :historyDwgSource, :historyDwgApprovedDate, :historyDwgReleaseDate, :historyDwgStatus, :historyDwgPrecedence, :historyDwgComments)");
query.bindValue(":historyDate", currDate.toString("MM-dd-yyyy")); //THIS IS THE PROBLEM.
query.bindValue(":historyDwgNumber", aeddlg.addEditDwgNumberEdit->text());
query.bindValue(":historyDwgTitle", aeddlg.addEditDwgTitleEdit->text());
query.bindValue(":historyDwgEngineer", aeddlg.addEditEngineerEdit->text());
query.bindValue(":historyDwgDateToCad", aeddlg.addEditDateToCadEdit->text());
query.bindValue(":historyDwgDateRequired", aeddlg.addEditDateRequiredEdit->text());
query.bindValue(":historyDwgDateReturnedFromCad", aeddlg.addEditDateReturnedEdit->text());
query.bindValue(":historyDwgDraftsman", aeddlg.addEditDraftsmanEdit->text());
query.bindValue(":historyDwgSource", aeddlg.addEditSourceEdit->text());
query.bindValue(":historyDwgApprovedDate", aeddlg.addEditApprovedEdit->text());
query.bindValue(":historyDwgReleaseDate", aeddlg.addEditReleasedEdit->text());
query.bindValue(":historyDwgStatus", aeddlg.addEditStatusComboBox->itemText(aeddlg.addEditStatusComboBox->currentIndex()));
query.bindValue(":historyDwgPrecedence", aeddlg.addEditPrecedenceEdit->text());
query.bindValue(":historyDwgComments", aeddlg.addEditCommentsEdit->toPlainText());

if(!query.exec())
{
QMessageBox::warning(this, tr("Warning"),
tr("Database Error: Unable to Insert New Entry into History"), QMessageBox::Ok);
}