Hello Team,
When I click save instead saving the data it duplicate same data mutilple time.
private void SaveBill() { try { if (DGVClientBill.Rows.Count > 0) { // update product qty if (MessageBox.Show("Please confirm if you want to save this record?", stitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { for (int i = 0; i < DGVClientBill.Rows.Count; i++) { con.Open(); SqlCommand cmd = new SqlCommand("insert into tblSales(SDate,SProductName,SPrice,SQty, SAmount,SCustomer)values(@sDate,@sProductName,@sPrice,@sQty, @sAmount,@sCustomer)", con); cmd.Parameters.AddWithValue("@sDate", dtBillindDate.Value.ToString("dd-MM-yyyy")); cmd.Parameters.AddWithValue("@sProductName", txtProductName.Text); cmd.Parameters.AddWithValue("@sPrice", txtSellingPrice.Text); cmd.Parameters.AddWithValue("@sQty", txtQuantity.Text); cmd.Parameters.AddWithValue("@sAmount", Convert.ToDecimal(DGVClientBill.Rows[i].Cells["dgvTotal"].Value.ToString())); cmd.Parameters.AddWithValue("@sCustomer", txtCustomer.Text); cmd.ExecuteNonQuery(); con.Close();
MessageBox.Show("Bill successfully saved !", "POS", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
// Clear();
} catch (Exception Ex) {
con.Close(); MessageBox.Show(Ex.Message); } }