private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
string connectionString = null;
connectionString = ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString;
con.ConnectionString = connectionString;
string cmd1 = "insert into Ledger([Account],[AccountNumber],[Date],[Description],[Post_Ref],[Debit],[Credit],[Balance])values(?,?,?,?,?,?,?,?)";
OleDbCommand cmd = new OleDbCommand(cmd1, con);
con.Open();
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Account",dataGridView1.Rows[e.RowIndex].Cells["Account"].Value.ToString());
cmd.Parameters.AddWithValue("@AccountNumber",int.TryParse(dataGridView1.Rows[e.RowIndex].Cells["AccountNumber"].Value));
cmd.Parameters.AddWithValue("@Date", DateTime.TryParse(dataGridView1.Rows[e.RowIndex].Cells["Date"].Value));
cmd.Parameters.AddWithValue("@Description", dataGridView1.Rows[e.RowIndex].Cells["Description"].Value.ToString());
cmd.Parameters.AddWithValue("@Post_Ref", dataGridView1.Rows[e.RowIndex].Cells["Post_Ref"].Value.ToString());
cmd.Parameters.AddWithValue("@Debit", Int32.TryParse(dataGridView1.Rows[e.RowIndex].Cells["Debit"].Value));
cmd.Parameters.AddWithValue("@Credit", Int32.TryParse(dataGridView1.Rows[e.RowIndex].Cells["Credit"].Value));
cmd.Parameters.AddWithValue("@Balance", Int32.TryParse(dataGridView1.Rows[e.RowIndex].Cells["Balance"].Value));
int n = cmd.ExecuteNonQuery();
con.Close();
Load_data();
}