for (i = 0; i < dataGridView1.Rows.Count; i++)
{
string query = "insert into Installments(Installment_no,Loan_id,Date,Amount)values(@Installment_no,@Loan_id,@Date,@Amount)";
cmd = new SqlCommand(query, cn);
cmd.Parameters.AddWithValue("@Loan_id", dataGridView1.Rows[i].Cells["Loanid"].Value);
cmd.Parameters.AddWithValue("@Date", dataGridView1.Rows[i].Cells["Date"].Value);
cmd.Parameters.AddWithValue("@Amount", dataGridView1.Rows[i].Cells["Amount"].Value);
cmd.Parameters.AddWithValue("@Installment_no", dataGridView1.Rows[i].Cells["installmentno"].Value);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
MessageBox.Show("Record Stored Successfully", "Success Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}