hi,
i have made a windows form in where i used Datagridview . i want to insert data in datagridview
and save data in three tables at a time. i have used OLEDB database.
how could i write this code?
How to insert Access data in more than three tables from the “datagridview” control?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Master BillaRank #2,229 · 630 reputationPosted Sep 6, 2009, 11:01 PM EDT
Just simple example
rivate void button3_Click(object sender, EventArgs e)
{
using (OleDbConnection connection = new OleDbConnection("constring"))
{
if (connection.State != ConnectionState.Open)
{
connection.Open();
}
using (OleDbTransaction trans = connection.BeginTransaction())
{
try
{
foreach (DataGridViewRow item in dataGridView1.Rows)
{
OleDbCommand cmdCommon = new OleDbCommand();
cmdCommon.CommandText = "Your first table insert query";
cmdCommon.ExecuteNonQuery();
cmdCommon.CommandText = "Your second table isnert query";
cmdCommon.ExecuteNonQuery();
}
trans.Commit();
}
catch (Exception ex)
{
trans.Rollback();
throw ex;
}
}
}
}
You can read value from the every row and make query and pass to command.
thank you