Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Data base is not getting updated in different session
QtWS25 Last Chance

Data base is not getting updated in different session

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 414 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    holeygaurav
    wrote on last edited by
    #1

    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:

    1. Data is stored in DB for a very first session through insert query.
    2. 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...
    3. 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.
    4. The update query is also not working; but in debugger mode it shows true return value.
    5. 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

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved