开发者

Database creation error in Qt

I am using this code to create a database. But I am getting "false" in debug. I tried a lot but its not working. What is the error in this?

 QSqlQuery query;
qDebug() << query.exec("CREATE TABLE glucose (id INTEGER PRIMARY KEY AUTOINCREMENT, value INTEGER, date TEXT, time TEXT, duration TEXT, note TEXT");

   qDebug() << query.prepare("INSERT INTO glucose(id, value, date, time, duration, note)""VALUES(?, ?, ?, ?, ?, ?)");

   query.bindValue(1,edit_glucose->text().toInt());

   query.bindValue(2,datetime->date());

  query.bindValue(3,datetime->time());

  query.bi开发者_如何学PythonndValue(4,"a");

   query.bindValue(5,edit_note->toPlainText());
   qDebug() << query.exec();


you forget to close your CREATE TABLE query with ")"


QSqlQuery has the method lastError(), returns error information :)


You are passing in the INSERT query the id field. You must remove it.

The query should be:

Debug() << query.prepare("INSERT INTO glucose(value, date, time, duration, note) 
                                      VALUES(?, ?, ?, ?, ?)");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜