发布网友 发布时间:2022-05-01 21:03
共2个回答
懂视网 时间:2022-05-02 01:24
<QDebug> #include <QSqlDatabase> #include <QSqlQuery> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName("student.db"); if(!db.open()) { qDebug() << "open err"; } else { qDebug() << "database is ok"; } QSqlQuery query(db); bool isok = query.exec("create table stud(id int primary key,name varchar(20))"); query.exec("insert into stud values(111,‘liming‘)"); query.exec("insert into stud values(102,‘li‘)"); query.exec("insert into stud values(103,‘lisi‘)"); query.exec("insert into stud values(105,‘zhangsan‘)"); if(!isok) { qDebug() << "table err"; } else { qDebug() << "table is ok"; } query.exec("select * from stud"); while(query.next()) { qDebug() << "id:"<<query.value(0).toInt()<<"name:"<<query.value(1).toString(); } return a.exec(); }
qt连接数据库Sqlite
标签:insert basename [] set data include tab bug arch
热心网友 时间:2022-05-01 22:32
如何进入QT自待的SQLite数据库