Results 1 to 10 of 10

Thread: Unable to work with database

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Unable to work with database

    Hi Guys,

    Not sure where I'm going wrong but here's my code:

    [CODE/] //Create a database (TO DO, close the database)
    QString strServerName = "LOCALHOSE\\SQLITE";
    QString strDBName = "test.db";

    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); //EDIT in final to incorporate multiple connections, will need a tracking variable that will track how many connections are opened and create a new unique one.
    /*
    db.setConnectOptions();
    QString dsn = QString("DRIVER={SQL Native Client}; SERVER=%1;DATABASE=%2;Trusted_Connection=Yes;").ar g(strServerName).arg(strDBName);
    db.setDatabaseName(dsn);
    */
    db.setDatabaseName(strDBName);

    bool dbOpen = db.open("test.db", NULL);
    if(dbOpen == TRUE)
    {
    qDebug() << "Database open";
    QSqlQuery query;
    query.exec("SELECT Row FROM tblField WHERE Page = one");
    qDebug() << query.lastError().text(); //if error executing SQL statement occurs, get error


    }
    if(dbOpen == FALSE)
    {
    qDebug() << "Last error " << db.lastError().text();
    }

    //Button cNav;

    db.close();
    db.removeDatabase("test.db");[\CODE]

    Basically I get the output of:

    Database open
    "no such table: tblField Unable to execute statement"

    Not sure why, I've got the database in the folder where the .exe is, in fact I've got in about 10 different folders just to be sure. I know that if it can't find a database, it'll create a new blank one, which I think is what is happening, question is, why?
    Last edited by Atomic_Sheep; 5th August 2013 at 12:26.

Similar Threads

  1. Replies: 0
    Last Post: 28th June 2013, 11:52
  2. Mysql unknown database, QMYSQL unable to connect
    By lixo1 in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2010, 21:39
  3. Replies: 9
    Last Post: 20th May 2010, 09:55
  4. ODBC Oracle. Unable to connect to database
    By egil in forum Qt Programming
    Replies: 2
    Last Post: 17th October 2008, 13:46
  5. which ide/editor/database work best with qt4?
    By kkool84 in forum Installation and Deployment
    Replies: 17
    Last Post: 24th August 2006, 06:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.