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?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Master BillaPosted Sep 7, 2009, 3:01 AM
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