希望大家都很好,我需要一些帮助,我需要更新一些文本框和listview项,我已经成功更新了文本框,但listview项保持不变,我想在更新时添加listview行,希望您理解我担心的请在这里提出一些想法是我的更新按钮代码
private void btnUpdate_Click_1(object sender, EventArgs e)
{
try
{
con = new SqlConnection(cs.DBConn);
con.Open();
String cb = "update Invoice_info set VATPer='" + txtTaxPer.Text + "',VATAmount='" + txttableno.Text + "',DiscountPer='" + txtDiscountPer.Text + "',DiscountAmount='" + txtDiscountAmount.Text + "',GrandTotal= '" + txtTotal.Text + "',TotalPayment= '" + txtTotalPayment.Text + "',PaymentDue= '" + txtPaymentDue.Text + "',Remarks='" + txtCustomerName.Text + "' where Invoiceno= '" + txtInvoiceNo.Text + "'";
cmd = new SqlCommand(cb);
cmd.Connection = con;
cmd.ExecuteReader();
con.Close();
for (int i = 0; i <= ListView1.Items.Count ; i++)
{
con = new SqlConnection(cs.DBConn);
string cd = "insert Into ProductSold(InvoiceNo,ProductID,ProductName,Quantity,Price,TotalAmount) VALUES (@d1,@d2,@d3,@d4,@d5,@d6)";
cmd = new SqlCommand(cd);
cmd.Connection = con;
cmd.Parameters.AddWithValue("d1", txtInvoiceNo.Text);
cmd.Parameters.AddWithValue("d2", ListView1.Items[i].SubItems[1].Text);
cmd.Parameters.AddWithValue("d3", ListView1.Items[i].SubItems[2].Text);
cmd.Parameters.AddWithValue("d4", ListView1.Items[i].SubItems[4].Text);
cmd.Parameters.AddWithValue("d5", ListView1.Items[i].SubItems[3].Text);
cmd.Parameters.AddWithValue("d6", ListView1.Items[i].SubItems[5].Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
btnUpdate.Enabled = true ;
MessageBox.Show("Successfully updated", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
我在标题中显示了相同的错误