QSqlQuery for ms access database
-
@mrshawn
I want something like this :SELECT * FROM names where name Like "*"&[, the text that you want to use as a prompt, and then ]&"*"
How should i write in query.prepare ?
wrote on 30 Aug 2019, 13:29 last edited by behruz montazeriquery.prepare("SELECT * FROM names where name Like '*'&[ st ]&'*' "); query.addBindValue(st);
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
What should i write to pass a parameter ?
-
wrote on 30 Aug 2019, 13:34 last edited by
Try changing
query.prepare("SELECT * FROM names where name Like '*'&[ st ]&'*' ");
to
QString st = "something"; query.prepare("SELECT * FROM names where name Like :st"); query.bindValue(":st", "*" + st + "*");
-
Try changing
query.prepare("SELECT * FROM names where name Like '*'&[ st ]&'*' ");
to
QString st = "something"; query.prepare("SELECT * FROM names where name Like :st"); query.bindValue(":st", "*" + st + "*");
wrote on 30 Aug 2019, 13:42 last edited by@mrshawn
There is no error but do not work. -
Can you write an example query that currently works for that use case ?
-
wrote on 30 Aug 2019, 16:45 last edited by
@sgaist
As i mentioned this one :QSqlQuery query ; query.prepare("SELECT * FROM names where name like ? "); query.addBindValue(st);
It works but i should write entire word i want to write a part of record in my case name record and it update QTableView
-
What I am asking for is an example without binding that is working. Once we have that it should be easier to come with a solution.
-
What I am asking for is an example without binding that is working. Once we have that it should be easier to come with a solution.
wrote on 1 Sept 2019, 10:23 last edited by@sgaist
I have no idea. -
wrote on 1 Sept 2019, 19:23 last edited by
Hi, the use of % instead of * is the right way. The * is only for using it directly on ms access query.
WHat version of ms access are you using? could you post a screenshot of your database/table?
-
Hi, the use of % instead of * is the right way. The * is only for using it directly on ms access query.
WHat version of ms access are you using? could you post a screenshot of your database/table?
wrote on 2 Sept 2019, 04:10 last edited by behruz montazeri 9 Feb 2019, 04:44@ronaldviscarral
Thanks for your response here is my screenshot :
link imaget -
Hi, the use of % instead of * is the right way. The * is only for using it directly on ms access query.
WHat version of ms access are you using? could you post a screenshot of your database/table?
wrote on 2 Sept 2019, 04:40 last edited by behruz montazeri 9 Feb 2019, 04:41This post is deleted! -
@sgaist
I have no idea.@behruz-montazeri said in QSqlQuery for ms access database:
@sgaist
I have no idea.Something like
"SELECT * FROM names where name like '%foo%'"
to confirm that one is working properly. -
@behruz-montazeri said in QSqlQuery for ms access database:
@sgaist
I have no idea.Something like
"SELECT * FROM names where name like '%foo%'"
to confirm that one is working properly.wrote on 2 Sept 2019, 07:03 last edited by behruz montazeri 9 Feb 2019, 10:05@sgaist
Yes that works.Then what should be inside the % % instead of foo for binding ???
what about binding ?? -
wrote on 2 Sept 2019, 19:28 last edited by
try this:
QSqlQuery query ; query.prepare("SELECT * FROM names where name like '%?%'" ); query.addBindValue("a");
-
wrote on 2 Sept 2019, 20:15 last edited by
I tested in Qt using access both 32 bits, this code works for me:
QString st = "a"; query->prepare("SELECT * FROM names WHERE name LIKE ?;"); QString criteria("%" + st + "%"); query->addBindValue(criteria);
-
I tested in Qt using access both 32 bits, this code works for me:
QString st = "a"; query->prepare("SELECT * FROM names WHERE name LIKE ?;"); QString criteria("%" + st + "%"); query->addBindValue(criteria);
wrote on 3 Sept 2019, 03:56 last edited by@ronaldviscarral
Thank you very much it works now.
19/24