Anand Deepen
Anand Deepen

Reputation: 11

Binding a datagridview to an access table

I work with VB.net 2010. I have in my form a datagridview which gets data from an Access table. Here is the code that creates the link :

  CS = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & FileNewName & ";Jet OLEDB:Database        Password=asd"
  Con.ConnectionString = CS
  Con.Open()

  Da = New OleDbDataAdapter("SELECT * from tblDetail where NoCompte = " & N.ToString, Con)
  Da.Fill(tblDet)

  DataGr.DataSource = tblDet

All this works perfectly well. All my data from my Access table is displayed in my Datagridview.

Then the user will make changes and I want of course the new data to be updated back to the Access table.

Isn't there a short way to do this or do I have to go line by line and use an OleDbCommand with SQL saying "update tblDetail set Name = ....."

Thanks for helping

Upvotes: 0

Views: 823

Answers (1)

jmcilhinney
jmcilhinney

Reputation: 54417

You use the same data adapter to save the changes as you used to retrieve the data. Fill executes the SelectCommand and Update executes the InsertCommand, UpdateCommand and DeleteCommand as required.

Upvotes: 1

Related Questions