Dear my friends...
I found QSqlSelectCursor on the doc.trolltech.com . I
want to use it for dynamic query.
I did like this:
void funonseqForm::sejarahSlot()
{
cid = QSpinBoxCustid->value();
QSqlDatabase * bd =
QSqlDatabase::addDatabase("QPSQL7", "OTHER");
bd->setHostName("192.168.23.237");
bd->setDatabaseName("kv");
bd->setUserName("postgres");
bd->setPassword("");
if ( ! bd->open() )
{
bd->lastError().showMessage();
}
QString stringsql = QString("select salesid,
report, emoicon, timestamp from //salesreport where
custid=%1").arg(cid);
QSqlSelectCursor * cur = new
QSqlSelectCursor(stringsql);
hisdataTable->setSqlCursor(cur, true, false);
hisdataTable->refresh();
}
But the application meet a trouble "An error occured
while accessing the database" if it executes the
"sejarahSlot()".
Where is my fault? is it because QSqlSelectCursor only
can not use a variable as its query string?
So how can I make a dynamic query with
QSqlSelectQuery?
Thank you very much.
--- Sean Harmer
Use QSpinBoxCustid->value() instead.
Sean
On Friday 06 August 2004 12:20, Prabu Subroto wrote:
Dear my friends...
I want to diplay the salesreports only for a determined customer (with custid) into a QDataTable. I use QSqlCursor for doing "select" from a view (false table).
I did like this: " void funonseqForm::sejarahSlot() { cid = QSpinBoxCustid->text(); QSqlDatabase * bd = QSqlDatabase::addDatabase("QPSQL7", "OTHER"); bd->setHostName("192.168.23.237"); bd->setDatabaseName("kv"); bd->setUserName("postgres"); bd->setPassword(""); if ( ! bd->open() ) { bd->lastError().showMessage(); }
QSqlCursor * cursor = new QSqlCursor("salesreport", true, bd); cursor.select("custid = %1").arg(cid); custdataBrowser->setSqlCursor(cursor, false); custdataBrowser->refresh(); } "
but I got this error message in compiling process
In file included from .ui/funonseqform.cpp:34: funonseqform.ui.h: In member function `virtual void funonseqForm::sejarahSlot()': funonseqform.ui.h:36: error: invalid conversion from `const char*' to `int' funonseqform.ui.h:48: error: request for member `select' in `cursor', which is of non-aggregate type `QSqlCursor*' make: *** [.obj/funonseqform.o] Error 1 patrixlinux@patrix:~/arsip/proyek/qt/kv/client>
how can I change the data type from the text of QSpinBox (QString) into "int"?
And how can I do a selection with QSqlCursor.select() but the value of cid variable must be whenever changeable.
Thank you very much in advance.
__________________________________ Do you Yahoo!? Yahoo! Mail is new and improved - Check it out! http://promotions.yahoo.com/new_mail