I have datagrid with two columns with multiple rows.
But in this code the loop runs only once. Why?
private void btnsave_Click(object sender, EventArgs e)
{
if (txtledger.Text.Length == 0)
{
MessageBox.Show("Fill all Infomation", "Exclamation!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
try
{
for (int i = 0; i < txtEnter.Rows.Count; i++)
{
par = txtEnter.Rows[i].Cells[0].Value.ToString();
amount1 = txtEnter.Rows[i].Cells[1].Value.ToString();
Comparbal();
quary = "INSERT INTO `account book` (`Traction Date`,Ledger,Particulars,`Vch Type`,Debits,Credits,FY,Narration)VALUES ('" + Vdate.Value.ToString("yyyy/MM/dd") + "','" + par + "','" + txtledger.Text + "','Payment'," + amount1 + ",0,'" + CFY + "','" + txtnar.Text + "')";
Connection.executenonquery(quary);
quary = "INSERT INTO `account book` (`Traction Date`,Ledger,Particulars,`Vch Type`,Debits,Credits,FY,Narration)VALUES ('" + Vdate.Value.ToString("yyyy/MM/dd") + "','" + txtledger.Text + "','" + par + "','Payment',0," + amount1 + ",'" + CFY + "','" + txtnar.Text + "')";
Connection.executenonquery(quary);
metroLabel2.Text = "Accounting Voucher:-" + (id + 1).ToString();
txtledger.SelectedIndex = -1;
txtEnter.CancelEdit();
particuars.Dispose();
amount.Dispose();
txtnar.Clear();
metroLabel2.Text = "";
txtEnter.Rows.Clear();
}
MessageBox.Show("Vouchar Post");
}
catch
{
MessageBox.Show("Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
What I have tried:
Thanks in advance. I want to make an account software. This code belongs to Payment Voucher