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

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();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.