View Full Version : SQL Question
^NyAw^
8th April 2008, 12:40
Hi,
I'm trying to open a connection to a DB.
This DB has two tables that I want to query some information.
My question is: Have I to make two connections using two "QSqlDatabase" opening the same DB but different table?
Second question is: I have created a ODBC driver (I'm using Windows), when opening the ODBC driver,where have I to tell it the name of the driver?
Thanks,
jacek
8th April 2008, 13:25
This DB has two tables that I want to query some information.
My question is: Have I to make two connections using two "QSqlDatabase" opening the same DB but different table?
You don't need the second connection, unless you want to have concurrent transactions.
Second question is: I have created a ODBC driver (I'm using Windows), when opening the ODBC driver,where have I to tell it the name of the driver?
In the setDatabaseName():
db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=myaccessfile.mdb");
^NyAw^
8th April 2008, 15:04
Hi,
Thanks, I have understood it now.
Do anyone knows if using Microsoft SQL 2005, the connections are permanent? So if not, is a good way to maintain them opened by using a QTimer that query something every X seconds?
Thanks,
^NyAw^
8th April 2008, 17:39
Hi,
I have another question:
I have a connection to a SQL Server using ODBC:
m_qBD = QSqlDatabase::addDatabase("QODBC","database1");
m_qBD.setHostName("localhost");
m_qBD.setDatabaseName("SQLServerODBC"); //Name of the ODBC driver that I have created
m_qBD.setUserName("user");
m_qBD.setPassword("passwd");
The DBServer have 2 Databases ("db1" and "db2").
The "db1" have 2 tables "table1" and "table2".
The "table1" has a filed called "field1".
How I get the information of the "field1"?
My problem is that the connection to the server is done, but don't how to open the Database "db1".
Thanks,
^NyAw^
8th April 2008, 17:54
Hi,
On creation of ODBC driver there is an option to select the default Database to be used.
So I created 2 drivers, one for each Database.
Thanks,
^NyAw^
8th April 2008, 19:36
Hi,
Finally found the correct way:
When want to make a query you can tell wich database and table want to query:
QString qQuery("select * from database1.table1");
So, don't need to create 2 drivers
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.