Results 1 to 9 of 9

Thread: connection with qsql module

  1. #1
    Join Date
    Jan 2009
    Posts
    54
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default connection with qsql module

    Hello.

    I am begginer with qsql module and I am trying to insert a new element in a database table. I dont know what i am doing wrong, because the conection is not opened. I am working with Windows 98.

    This is the code:
    Qt Code:
    1. db = QSqlDatabase::addDatabase( "QODBC" );
    2. db.setHostName("localhost");
    3. db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=C:\\Documents and Settings\\user1\\bbdd.mdb");
    4.  
    5.  
    6. if ( db.open() ) {
    7. // Database successfully opened; we can now issue SQL commands.
    8. QSqlQuery target;
    9. target.exec( "INSERT INTO Equipo ( serialNumber,uniNumber,description ) VALUES ( 1213,3423,sdfahsoew )" );
    10.  
    11. }
    12. db.close();
    To copy to clipboard, switch view to plain text mode 

    and it has never gone into the condition if.

    Cheers, and thank you in advance.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: connection with qsql module

    try to connect to your database using QTDIR/demos/sqlbrowser if it will not connect then try to put your database in dir path to which doesn't have spaces.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Jan 2009
    Posts
    54
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: connection with qsql module

    Ok, It is true that the puth it was too long, I put the database in the same directory of my project but the same problem continues, using the sqlbrowser tells:

    the data source wasnt specify and it wasnt specified any predetermined controler.

    have i to write only the driver and the database name bbdd.mdb?

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: connection with qsql module

    database connection string looks fine except spaces in path.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. The following user says thank you to spirit for this useful post:

    adamatic (24th February 2009)

  6. #5
    Join Date
    Jan 2009
    Posts
    54
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: connection with qsql module

    I can go into the if condtion now, but it isnt working the insertion in the table, is the insertion correct ?

  7. #6
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: connection with qsql module

    the third value in it seems to be a string, so try adding quotes to it

  8. #7
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: connection with qsql module

    or use QSqlQuery::addBindValue.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  9. #8
    Join Date
    Jan 2009
    Posts
    54
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: connection with qsql module

    Before try with addBindValue tell you that I obtained the following warning and maybe it is the reason:

    warning: Lowest section in C:\WINDOWS\system32\odbcint.dll is .rsrc at 1f841000

    Because I could check that the connection with the database it is well done because when I have the database opens and program execution generates a .ldb. Although the access to the table is not working.

  10. #9
    Join Date
    Jan 2009
    Posts
    54
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: connection with qsql module

    Ok, I have just found the error, it was that i was writing double quotes( " ) and it must be simples ( ' ).

    Sorry but thank for your time. Maybe this can advise someone about quotes.

    Cheers

Similar Threads

  1. SQL connection closure problem.
    By cbarmpar in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2008, 09:42
  2. Client/Server Error: BadIDChoice
    By 3nc31 in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2007, 11:22
  3. Font differences and how to mitigate
    By PrimeCP in forum Qt Programming
    Replies: 7
    Last Post: 23rd July 2007, 23:55

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.