简体   繁体   English

使用qt在SQLITE数据库中插入多行

[英]Inserting Multiple Rows In A SQLITE Database Using qt

Hello I am trying to insert multiple rows (two in this case) into a SQLITE database using qt 5.4. 您好,我正在尝试使用qt 5.4将多行(在这种情况下为两行)插入SQLITE数据库。 I have been following the documentation but the program has been crashing and I can not explain why. 我一直在关注文档,但是程序崩溃了,我无法解释原因。

query_Invoice.prepare("INSERT INTO Invoice VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
QVariantList Invoice_Number, Date_Time, Total_Purchased, Qty, Description, Product_CODE, Unit_Price, Total_Price, Goods_Total, VAT_Invoice, Company_ID;
Invoice_Number << 1 << 2;
Date_Time << 1776-07-04 << 1776-07-05;
Total_Purchased << 2 << 3;
Qty << 50 << 60;
Description << "Paint" << "Drill" << QVariant(QVariant::String);
Product_CODE << "EEFF2" << "EEF23" << QVariant(QVariant::String);
Unit_Price << 12 << 13;
Total_Price << 53 << 66;
Goods_Total << 70 << 80;
VAT_Invoice << 55 << 66;
Company_ID << 1 << 2;
query_Invoice.addBindValue(Invoice_Number);
query_Invoice.addBindValue(DateTime);
query_Invoice.addBindValue(Total_Purchased);
query_Invoice.addBindValue(Qty);
query_Invoice.addBindValue(Description);
query_Invoice.addBindValue(Product_CODE);
query_Invoice.addBindValue(Unit_Price);
query_Invoice.addBindValue(Total_Price);
query_Invoice.addBindValue(Goods_Total);
query_Invoice.addBindValue(VAT_Invoice);
query_Invoice.addBindValue(Company_ID);
query_Invoice.execBatch();
qDebug() << query_Invoice.executedQuery();
qDebug() << query_Invoice.lastError();

Start by trying to successfully insert one row. 首先尝试成功插入一行。 You'll need to specify which columns in the table that the values correspond to. 您需要指定表中值对应的列。

query_Invoice.prepare( "INSERT INTO Invoice ( column_name1, column_name2, column_name3 ) VALUES ( ?,?,? )" );

Also, addBindValue( DateTime ) should be addBindValue( Date_Time ) . 另外, addBindValue( DateTime )应该是addBindValue( Date_Time )

And, 和,

query_Invoice.prepare("INSERT INTO Invoice VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); <---- Closing paren after last '?'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM