void accessdb::connectDB()
{
}if(QSqlDatabase::contains("qt_sql_default_connection"))
db = QSqlDatabase::database("qt_sql_default_connection");
else
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("qq.db");
if(!db.open())
{
QMessageBox::warning(NULL, "Open DB", tr("Open DB error:%1").arg(db.lastError().text()));
}
QSqlQuery query;
query.prepare("create table user(id varchar(15) not null primary key,passwd varchar(15) not null,nickname varchar(15) null)");
if( !query.exec() )
{
QMessageBox::warning(NULL, "Create Table", tr("Create Table error:%1").arg(query.lastError().text()));
}
}
我先打开数据库,没有问题,就是运行到新建表的时候报错
提示:Create Table error:No query Unable to fetch row
1 个解决方案
#1
改成这样就好了,不知道为什么啊
QSqlQuery query;
if( !query.exec("create table user(id varchar primary key,passwd varchar,nickname varchar null)") )
{
QMessageBox::warning(NULL, "Create Table", tr("Create Table error:%1").arg(query.lastError().text()));
}
QSqlQuery query;
if( !query.exec("create table user(id varchar primary key,passwd varchar,nickname varchar null)") )
{
QMessageBox::warning(NULL, "Create Table", tr("Create Table error:%1").arg(query.lastError().text()));
}
#1
改成这样就好了,不知道为什么啊
QSqlQuery query;
if( !query.exec("create table user(id varchar primary key,passwd varchar,nickname varchar null)") )
{
QMessageBox::warning(NULL, "Create Table", tr("Create Table error:%1").arg(query.lastError().text()));
}
QSqlQuery query;
if( !query.exec("create table user(id varchar primary key,passwd varchar,nickname varchar null)") )
{
QMessageBox::warning(NULL, "Create Table", tr("Create Table error:%1").arg(query.lastError().text()));
}