PDA

View Full Version : Unable to fetch data when searching through select query



sinha.ashish
10th April 2008, 06:31
void VistaMedia::search()
{
QString searchText=searchTextLineEdit->text();
QSqlQuery query;
query.prepare("SELECT title FROM mediadetails WHERE title LIKE ' %:title% ' "); query.bindValue(":title",searchText);
query.exec();
while(query.next())
listWidget->addItem(query.value(0).toString());
QSqlError e=query.lastError () ;
QMessageBox::information(this,"problem",e.text());
}



table details are as :
mediadetails
----------------
|title|

F_1.avi
F_2.avi
11.dat
music.dat
jazz.avi

i am entering in the search text " f ".
there is a error message shows "unable to fetch data". what to do????

sinha.ashish
10th April 2008, 07:15
void VistaMedia::search()
{
QString serachText=searchTextLineEdit->text().trimmed();
int noOfItems=listWidget->count();
while(noOfItems>0)
{
if(!(listWidget->item(noOfItems-1)->text().contains(mname, Qt::CaseInsensitive)))
{
listWidget->removeItemWidget ( listWidget->item(noOfItems-1));
delete listWidget->item(noOfItems-1);
}
l--;
}
}


I have solved my problem in another way ,just using listwidget's functions,without using query.its fast and better.Thanks to all replies ....

sinha.ashish
10th April 2008, 11:37
but i want the solution for previous problem ..................
becoz now i must fetch data from mysql table.....
for advance search in which i have to match the entered data with relevent colums specified.....
so, guys....plzzz suggest me...


void VistaMedia::search()
{
QString searchText=searchTextLineEdit->text();
QSqlQuery query;
query.prepare("SELECT title FROM mediadetails WHERE title LIKE ' %:title% ' "); query.bindValue(":title",searchText);
query.exec();
while(query.next())
listWidget->addItem(query.value(0).toString());
QSqlError e=query.lastError () ;
QMessageBox::information(this,"problem",e.text());
}



table details are as :
mediadetails
----------------
|title|

F_1.avi
F_2.avi
11.dat
music.dat
jazz.avi

i am entering in the search text " f ".
there is a error message shows "unable to fetch data". what to do????

jacek
10th April 2008, 15:06
Please, don't post the same question more than once.