Hi

How can I get the row id of a record added by QSqlQuery::exec("INSERT ...") if it is automatically assigned by the database?

There is an old thread on a closely related topic (see http://www.qtcentre.org/forum/f-qt-p...mit-12908.html), but the proposed solutions did not work for me:

  • lastInsertedId(): not supported by database or driver (Microsoft Access, QODBC)
  • bind NULL, i.e., QVariant(QVariant::Int) with QSql::ParamType InOut: QSqlQuery::exec fails with the message "you tried to assign the Null value to a variable that is not a Variant data type" (yes, I tried; how else can I bind a Null value if not as variant?)
  • bind NULL, i.e., QVariant(QVariant::Int) with QSql::ParamType Out: QSqlQuery::exec fails with the message "Optional feature not implemented"


My current workaround is very ugly: I insert the record with a modified field (I add 100 to an int field that is in reality maximally 10), then SELECT .... WHERE value > 100, store the row id, then UPDATE with the corrected value).

Any less cumbersome method is highly appreciated.

Al_