Qt Creator Sql Update语法错误



我在qt creator中获得sql语法错误的更新命令。

QSqlQuery q,q2;
for(int r=0; r<rowtablecount; r++){
    q.prepare("update checkdata set "
              "alobs=:alobs,"
              "payee_name=:payee_name,"
              "payee_nature=:payee_nature,"
              "account_code=:account_code,"
              "amount=:amount,"
              "date_paid=:date_paid,"
              "cancel_status=:cancel_status,"
              "reviewer=:reviewer,"
              "preparer=:preparer,"
              "reciever=:reciever,"
              "reviewer_pos=:reviewer_pos,"
              "preparer_pos=:preparer_pos,"
              "reciever_pos=:reciever_pos,"
              "date_delivered=:date_delivered"
              "where check_no = :checkno");
    q.bindValue(":checkno", tabledata[r][2]);
    qDebug() << tabledata[r][2];
    q.bindValue(":alobs",tabledata[r][3]);
    q.bindValue(":payee_name",tabledata[r][4]);
    q.bindValue(":payee_nature",tabledata[r][5]);
    q.bindValue(":account_code",tabledata[r][6]);
    q.bindValue(":amount",tabledata[r][7].toDouble());
    q.bindValue(":date_paid",tabledata[r][10]);
    q.bindValue(":reviewer",reviewer);
    q.bindValue(":preparer",preparer);
    q.bindValue(":reciever",reciever);
    q.bindValue(":reviewer_pos",reviewer_pos);
    q.bindValue(":preparer_pos",preparer_pos);
    q.bindValue(":reciever_pos",reciever_pos);
    q.bindValue(":date_delivered",tabledata[r][9]);
    q.bindValue(":acicn", acic_value);
    q2.prepare("update acic set date_prepared=:date_prepared, total_amount=:total_amount where acic_num=:acic_num");
    q2.bindValue(":date_prepared",tabledata[r][1]);
    q2.bindValue(":total_amount",tabledata[r][8]);
    q2.bindValue(":acic_num", acic_value);
    if(!q.exec()){
        if(q.lastError().isValid())
            qDebug() << q.lastError().text() << " <error " << r;
        QMessageBox::critical(this,tr("Error: Entry Failed"),tr("Data Field incorrect."));
    if(!q2.exec()){
        if(q2.lastError().isValid())
            qDebug() << q2.lastError().text() << " <error " << r;
        QMessageBox::critical(this,tr("Error: Entry Failed"),tr("Data Field incorrect."));
从上面,我得到了这个错误,由于for循环重复了3次:

"你的SQL语法有错误;检查与你的MySQL服务器版本对应的手册,在第1行'check_no = '1248973 "附近使用正确的语法QMYSQL: cannot to execute query"

我怀疑是在prepare中写了命令,或者可能是保留字,但是我找不到它。

看不出这一点,我好像是个十足的白痴。错误在"where check_no =:check_no"前一行。它只需要一个空格。

感谢Abhik Chakraborty指出来

最新更新