【问题标题】:When try to insert into table i am getting QSqlError("", "Parameter count mismatch", "") here is my query当尝试插入表时,我得到 QSqlError("", "Parameter count mismatch", "") 这是我的查询
【发布时间】:2016-09-14 05:15:06
【问题描述】:
   QSqlQuery insert_emi_query;
   insert_emi_query.prepare("INSERT INTO emi_info (emi-info_id, customer_id, down_payment, emi_start_date, emi_end_date, emi_amount, toatl_emi, intrest_rate, total_emi_amount) "
                 "VALUES(:emi-info_id, :customer_id, :down_payment, :emi_start_date, :emi_end_date, :emi_amount, :toatl_emi, :intrest_rate, :total_emi_amount)");
   insert_emi_query.bindValue(":emi-info_id",emi_id);
   insert_emi_query.bindValue(":customer_id",cutomer_id);
   insert_emi_query.bindValue(":down_payment",ui->txtEMIDownPayment->text().toInt());
   insert_emi_query.bindValue(":emi_start_date",ui->dateEMIStart->date());
   insert_emi_query.bindValue(":emi_end_date",ui->dateEMIEnd->date());
   insert_emi_query.bindValue(":emi_amount",ui->txtEMIPerMonth->text().toInt());
   insert_emi_query.bindValue(":toatl_emi",ui->spinEMI->text().toInt());
   insert_emi_query.bindValue(":intrest_rate",ui->txtEMIRate->text().toInt());
   insert_emi_query.bindValue(":total_emi_amount",ui->txtEMIAfterPayment->text().toInt());
   if(insert_emi_query.exec()){
       qDebug() << "EMI Info Added---------------------";
   }else{
       qDebug() << "EMi not inserted" << insert_emi_query.lastError();
   }

【问题讨论】:

  • 您能否提供有关您尝试插入的表的架构的更多信息?
  • 很好,现在看起来可读了。

标签: c++ qt sqlite


【解决方案1】:

:emi-info_id 不是有效的parameter name- 不允许出现在未加引号的标识符中,并且参数名称不能被引用)。

【讨论】:

    【解决方案2】:

    我无法编辑您的问题。也许您想自己编辑它,使用以下 sn-p,以提高理解力。

    1) “emi-info_id”中的破折号对吗?大多数数据库不允许在列名中使用破折号。

    2) 您可能想检查您是否为表的所有必填列指定了值。

    QSqlQuery insert_emi_query;
    
    insert_emi_query.prepare("                                         "
    "                                                                  "
    "INSERT INTO emi_info (                                            "
    "   emi-info_id, customer_id, down_payment, emi_start_date,        "
    "   emi_end_date, emi_amount, toatl_emi, intrest_rate,             "
    "   total_emi_amount)                                              "
    "                                                                  "
    "                                                                  "
    "VALUES(                                                           "
    "   :emi-info_id, :customer_id, :down_payment, :emi_start_date,    "
    "   :emi_end_date, :emi_amount, :toatl_emi, :intrest_rate,         "
    "   :total_emi_amount)                                             "
    "                                                                  "
    );
    
    insert_emi_query.bindValue(":emi-info_id",emi_id);
    insert_emi_query.bindValue(":customer_id",cutomer_id);
    insert_emi_query.bindValue(":down_payment",ui->txtEMIDownPayment->text().toInt());
    insert_emi_query.bindValue(":emi_start_date",ui->dateEMIStart->date());
    
    insert_emi_query.bindValue(":emi_end_date",ui->dateEMIEnd->date());
    insert_emi_query.bindValue(":emi_amount",ui->txtEMIPerMonth->text().toInt());
    insert_emi_query.bindValue(":toatl_emi",ui->spinEMI->text().toInt());
    insert_emi_query.bindValue(":intrest_rate",ui->txtEMIRate->text().toInt());
    insert_emi_query.bindValue(":total_emi_amount",ui->txtEMIAfterPayment->text().toInt());
    
    if(insert_emi_query.exec()) {
       qDebug() << "EMI Info Added---------------------";
    }
    else{
       qDebug() << "EMi not inserted" << insert_emi_query.lastError();
    }
    

    【讨论】:

      【解决方案3】:

      您查询中的列名emi-info_id 似乎是错字。它应该是 emi_info_id。因为- 的列名无效。

      如果您使用的是 Qt5(我不知道 qt4 中有什么)或更高版本,那么您会得到类似

      的错误类型
      insert_emi_query.lastError().type()
      

      在上述情况下,它应该是QSqlError::StatementError,因为列名中有错字。

      【讨论】:

        猜你喜欢
        • 2022-11-03
        • 2015-09-23
        • 2010-12-06
        • 2015-03-09
        • 2022-06-23
        • 2022-10-04
        • 1970-01-01
        • 2020-05-13
        • 1970-01-01
        相关资源
        最近更新 更多