0

Hello and thanks for any help you may give to me in advance.

Im using vb.net 2010. MS Access 2007 database and a datagridview.

I have a problem, I want to add/delete/edit data to bound datagridview and will automatically update the database (which is the MS Access 2007 database - Data Provider OLEDB)

Can someone give me an idea of the necessary syntax that I will need to accomplish this goal?

Thanks

2
Contributors
1
Reply
25
Views
4 Years
Discussion Span
Last Post by AmrMohammed
0

Greetings,

I think the easiest way to do it is creating a DataSet and a SqlDataAdapter instances.
When a CellEndEdit event occurs on DataGridView you simply first call the Update method on SqlDataAdapter instance giving it the table within the DataSet instance as an argument then call the AcceptChanges() method on the DataSet instance.

SqlDataAdapter oda = new SqlDataAdapter();
DataSet ds = new DataSet();
..............
..............
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{             //when done the Cell edit, the datasource and the database will be changed

SqlCommandBuilder local = new SqlCommandBuilder(oda);

oda.UpdateCommand = local.GetUpdateCommand();

oda.Update(ds.Tables[0]);

ds.AcceptChanges();
}

Edited by AmrMohammed

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.