PDA

View Full Version : Select and Insert commands failed while writing in to MDB Files



sateeshlankapalli
2nd February 2010, 09:07
Hi All,

I'm a newbie in to this forum. If i posted it in the wrong place, please excuse me. I'm writing a QT program which has to access the MDB file for read and write. When run the program it was connected properly to the database. But while selecting or inserting in the data in to MDB files it was getting failed.

I'm pasting my code in below:

#include "msaccess.h"
#include "ui_msaccess.h"

MSAccess::MSAccess(QWidget *parent) :
QWidget(parent),
ui(new Ui::MSAccess)
{
ui->setupUi(this);
ConnectToDB();
}

MSAccess::~MSAccess()
{
delete ui;
}

void MSAccess::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
bool MSAccess::ConnectToDB()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setHostName("localhost");
db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=C:/Program Files/NARADA PRODUCTS/MMS/Data/MMS.mdb");
if (!db.open()) {
qmb.critical(0, QObject::tr("Database Error"),
"DataBase Connection Failed");
return false;
}
else
{
qmb.information(this,"DataBase Connection","Connection Opened Successfully",QMessageBox::Ok);
}
return true;
}

void MSAccess::on_bu_get_clicked()
{
QString term_id="";
QString store_id="";
QStringList Rs;
QSqlQuery sel_query;

if(!sel_query.exec("select term_id from pos_terminal where rownum<2"))
{
qmb.information(this,"Select query status","select query was Failed",QMessageBox::Ok);
}

term_id = sel_query.value(0).toString();
qmb.information(this,"Terminal Id",term_id,QMessageBox::Ok);
ui->le_term_id->setText(term_id);

}

void MSAccess::on_bu_set_clicked()
{
QSqlQuery query("insert into pos_terminal(term_id,store_id) values('12345678')");
query.exec();
QSqlDatabase::database().commit();
}

When i'm trying to set data then i'm getting this error:

QODBCResult::exec: Unable to execute statement: " [Microsoft][ODBC Driver Manager] Function sequence error"


Please tel me the solution for the above problem. It's urgent.

With Regards,
Sateesh Lankapalli