c# - 我想在更新我的工作时更新 TextBoxes 并添加 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();
//int i = 1;
//ListView1.BeginUpdate();
//ListView1.Items.Clear();
// //var item = new bool
//foreach (var item in items )
//{
// ListViewItem row = new ListViewItem(i.ToString());
// row.SubItems.Add(item.EventId);
// row.SubItems.Add(item.Name);
// row.SubItems.Add(item.WordPos);
// lstXmlItems.Items.Add(row);
// i++;
//}
//ListView1.EndUpdate();
//ListView1.Refresh();
//for (int i = 0; i <= ListView1.Items.Count ; i++)
for (int i = 0; i < ListView1.Items.Count - 1; 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);
}
}
解决方案
推荐阅读
- graphql - 无法将自定义结果从解析器传递到 Graphql
- django - django - 如何获取团队的所有项目?
- javascript - PhaserJS 3.0 如何将图像放置在屏幕右下方?
- reactjs - InvalidValueError:setMap:不是 Map 的实例;而不是 StreetViewPanorama @react-google-maps/api 的实例
- r - 将具有许多块的字符串向量转换为具有标头的数据帧
- swift - 如何使 SKSpritenode 移动到 swift SpriteKit 中的触摸位置
- c++ - 为什么我的代码在执行时的初始嵌套 for 循环中进入无限循环?
- linux - 如何在 vi 编辑器 linux 中删除新行?
- flutter - 在 Flutter 中使用两个不同的键验证 TextformField
- iccube - 如何在 IcCube 中设置柱形图的笔触颜色