do you know how to check if a record exist in qt ?..
do you know how to check if a record exist in qt ?..
what i would like to do is .. i listing all the members in a drop box which the names are from across 2 database tables ...
so i would like to check if this record exist in the first table .. else check in table 2.. then proceed to do something..
but i am stuck on how to check if a record exist in qt.. i am using sqlite.
Re: do you know how to check if a record exist in qt ?..
You execute a query looking for the record and see if it returns any rows. There is nothing Qt-specific about this.
Code:
bool ok;
bool foundBoth = false;
ok = q.exec("select 1 from table1 where field = value");
if (ok && q.next()) {
ok = q.exec("select 1 from table2 where field = value");
if (ok && q.next()) {
foundBoth = true;
}
}
Use bound parameters if there is any chance the value can be supplied directly by the user or contain semicolons, quotes etc. Heck, just use bound parameters anyway.