I have changed my DSN and now another problem occured:
database_manager_
= QSqlDatabase::addDatabase("QODBC3",
"test_qt");
database_manager_.setDatabaseName("MySQL_Test");
// database_manager_.setDatabaseName("Driver={MySQL_Test};USER=karan;Password=karan;SERVER=localhost;");
database_manager_.setHostName("localhost");
database_manager_.setUserName("karan");
database_manager_.setPassword("karan");
database_manager_ = QSqlDatabase::addDatabase("QODBC3", "test_qt");
database_manager_.setDatabaseName("MySQL_Test");
// database_manager_.setDatabaseName("Driver={MySQL_Test};USER=karan;Password=karan;SERVER=localhost;");
database_manager_.setHostName("localhost");
database_manager_.setUserName("karan");
database_manager_.setPassword("karan");
To copy to clipboard, switch view to plain text mode
when i execute the above code it gives me :
("QSQLITE", "QMYSQL", "QMYSQL3", "QODBC", "QODBC3")
Driver available : true
Database opened successfully
"MySQL_Test"
createEmployeeTable : false
getProfileRecords EXEC : false
("QSQLITE", "QMYSQL", "QMYSQL3", "QODBC", "QODBC3")
Driver available : true
Database opened successfully
"MySQL_Test"
QSqlQuery::exec: database not open
createEmployeeTable : false
QSqlQuery::exec: database not open
getProfileRecords EXEC : false
To copy to clipboard, switch view to plain text mode
Hopefully that means it connects to the DSN and database got opened but why it gives error as "database not open" when i want to create a table.
what is the problem here please help...
Added after 1 32 minutes:
:P
I got the solution... :
Just missed to pass the QSqlDatabase object in QSqlQuery ...
query.exec("SELECT * FROM table_name");
QSqlQuery query(database_object);
query.exec("SELECT * FROM table_name");
To copy to clipboard, switch view to plain text mode
Bookmarks