Data base is not getting updated in different session
-
Dear All,
I am just the novice in this field...i am writing an application where i want to store the data in to the database.
my doubts are as under:
- Data is stored in DB for a very first session through insert query.
- The DB connection is shown as disconnected for subsequent session...even if we tried to open the DB connection deliberately in the same window ...data wont get stored...
- I am using the same code for this application which was tried and tested in my earlier application, the only difference is i am working windows7 before the application was deployed successfully on winxp.
I have also check the permissions of DB file for my earlier application and this application and are found to be same. - The update query is also not working; but in debugger mode it shows true return value.
- My structure of application is:=> Main Window-> Call to initdatabase->child window-> Adding data in DB fields.
@
void MainWindow::Initdatabase()
{
db = QSqlDatabase::addDatabase("QSQLITE");
db.setHostName("localhost");
db.setDatabaseName("SecureFirst");
db.setUserName("root");
db.setPassword("root");
db.open();
QSqlQuery query("SecureFirst");
db.transaction();query.prepare("SELECT name FROM sqlite_master WHERE type =:table AND name = :tablename"); query.bindValue(":table", "table"); query.bindValue(":tablename", "SecureData"); query.exec(); if(!query.next()){ //if table does not exists query.exec("create table SecureData (CardNo varchar,MemberName varchar,Mobile varchar,Address varchar,SchemeName varchar,SchemeDuration varchar,Date varchar,Paymode varchar,Amount varchar,Agent varchar)"); query.exec("create table Authentication(Name varchar,Password varchar) "); query.exec("INSERT INTO Authentication (Name,Password) VALUES ('admin','1234')"); db.commit(); }
}
@
and its implementation in child window...data insertion...
@
QSqlQuery("SecureFirst");
QSqlQuery query;
bool c,x,y,z;
x= db.isOpen();
y = db.transaction();
// c = query.prepare("UPDATE SecureData SET MemberName=:MemberName,Mobile=:Mobile,Address=:Address,SchemeName=:SchemeName,SchemeDuration=:SchemeDuration,Date=:Date,PayMode=:PayMode,Agent=:Agent,CardNo=:CardNo");
query.prepare("INSERT INTO SecureData (CardNo,MemberName,Mobile,Address,SchemeName,SchemeDuration,Date,PayMode,Agent) VALUES (:CardNo,:MemberName,:Mobile,:Address,:SchemeName,:SchemeDuration,:Date,:PayMode,:Agent)");
query.bindValue(":CardNo",cardno);
query.bindValue(":MemberName",mname);
query.bindValue(":Mobile",mobile);
query.bindValue(":Address",address);
query.bindValue(":SchemeName",schemen);
query.bindValue(":SchemeDuration",duration);
query.bindValue(":Date",joining);
query.bindValue(":PayMode",paymode);
query.bindValue(":Amount",amount);
query.bindValue(":Agent",agent);
query.exec();z = db.isOpen(); c = db.commit(); QMessageBox::information(this,"Add Member Request","Data Saved Successfully");//Data Saved
@
please help me .... i may be wrong with the basics also....please guide..
Regards,
Gaurav