PDA

View Full Version : First last button suggestions



fnmblot
7th September 2006, 18:49
In my continuing quest for trying to build a database that tracks the music I have written, I have come to another wall. I am trying to insert 4 buttons in a form, First Next Prev and Last. Do you guys have any suggestions? I have checked the demos and examples and the documentation, but I don't really understand it. So far I have :

void nnDBSPieceViewForm::firstPushButtonSlot()
{ QSqlQuery query("SELECT piece_name FROM main ORDER BY uid");
query.exec();
query.first();
ui.pieceNameLineEdit->setText(query.value(0).toString());
qDebug("firstPushButton Pressed");
} // End firstPushButtonSlot
It compiles fine, but when I click the First button, in the console I receive:

QODBCResult::exec: Unable to execute statement:
[Microsoft][ODBC Driver Manager] Function sequence error
QSqlQuery::value: not positioned on a valid record
firstPushButton Pressed

Any suggestions?
Thanks in advance,

fnmblot

wysota
7th September 2006, 23:09
Try query.next() instead of query.first(). BTW. It doesn't have anything to do with buttons :)

fnmblot
8th September 2006, 14:52
Unfortunately, the query.next() did not work. I received the exact same error in the console. I think I will try a different approach this weekend, probably QSqlQueryModel. I was able to run SELECT queries that way before.

Thanks!
fnmblot

jacek
8th September 2006, 14:57
QSqlQuery query("SELECT piece_name FROM main ORDER BY uid");
query.exec();
You try to execute the query twice --- maybe that's the problem?

fnmblot
8th September 2006, 19:17
You were absolutely right! Looks like the second query was just sending an empty query, hence the error messages. I took that one out and the query executed just fine.

Once again, thank you guys so much! I don't know what I would do without you all.

fnmblot