Qt数据库之查询
用SQLite建了一个小型的数据库,但是在查询那块不是很懂,代码如下:
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(":memory:"); //将数据库建立在内存中
if(!db.open())
{
exit(0);
}
query = new QSqlQuery(db);
//建表
query->exec("create table student(stuId varchar primary key,name varchar,passwd varchar)");
//添加数据
query->exec("insert into student values('20101121','yuye','123456789')");
query->exec("insert into student values('20101122','tiankong','abcdefg')");
QString studentId = ui->LineEdit1->text(); //获取学号
QString passWd = ui->LineEdit2->text(); //获取密码