I am trying to perform a QSqlQuery with binding a value and am having problems. I have already executed an Insert with many binded values and that worked fine, but when I try to do a Select with binded values, I have no luck. My code snippet looks like:
Code:
QSqlQuery customer; customer.prepare( "SELECT Fname,Lname,StreetAddress,City,State,ZipCode,Phone FROM customer WHERE Cust_ID = :id " ); customer.bindValue( ":id", customerID ); customer.exec( ); qDebug( ) << customer.lastQuery();
I have also tried
Code:
QSqlQuery customer; customer.prepare( "SELECT Fname,Lname,StreetAddress,City,State,ZipCode,Phone FROM customer WHERE Cust_ID=?" ); customer.addBindValue( customerID ); customer.exec( ); qDebug( ) << customer.lastQuery();
Neither of these work. When I print lastQuery on the first snippet of code, it prints out:
So it obviously is ignoring the bind. Can I use a bind in this way or am I misunderstanding what binds do? Thanks!Quote:
"SELECT Fname,Lname,StreetAddress,City,State,ZipCode,Phone FROM customer WHERE Cust_ID = :id "
Added after 38 minutes:
It looks like I needed to add the QSql::Out as the second argument to the addBindValue( ) function call. Is this the correct thinking about why it works when I write the line this way:
Thanks for the clarification.