1

我正在将我的DataGridview数据发送到SQL database. 我已经创建并启动了连接。一切正常,但是当我的 . 中有多个 raw 时Datagridview,我会收到更多消息,这意味着每个 raw 都让我成功添加,我只需要收到一条消息。

private void buttonsave_Click(object sender, EventArgs e)
{
  InvoiceNew myobj = new InvoiceNew();
  myobj.Invoicedate = dateTimePicker1.Value;
  myobj.Invoiceno = textBoxInvoiceNo.Text;
  myobj.Invoicetotal = Convert.ToDouble(textboxtotal.Text);
  myobj.Balance = 0.00;
  myobj.Paidammount = Convert.ToDouble(textboxtotal.Text);

  myobj.AddInvoiceHeader(myobj);

  for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
  {
    InvoiceDetailNew myobjd = new InvoiceDetailNew();

    myobjd.Invoiceno = textBoxInvoiceNo.Text;
    myobjd.Itemcode = dataGridView1.Rows[i].Cells[0].Value.ToString();
    myobjd.Itemname = dataGridView1.Rows[i].Cells[2].Value.ToString();
    myobjd.Qty = 
        Convert.ToInt32(dataGridView1.Rows[i].Cells[1].Value.ToString());
    myobjd.Unitprice = 
        Convert.ToDouble(dataGridView1.Rows[i].Cells[3].Value.ToString());
    myobjd.Subtotal = 
        Convert.ToDouble(dataGridView1.Rows[i].Cells[4].Value.ToString());
    myobjd.AddInvoiceDetail(myobjd);

    main_menu myobj1 = new main_menu();
    myobj1.Show();
    this.Hide();
  }
}
4

0 回答 0