In the .NET framework, in order to save data into a databse item, one has to use:
Me.Validate();
Me.CustomersBindingSource.EndEdit();
Me.TableAdapterManager.UpdateAll(Me.CustomerDataSet);
Can someone explain me why? What's going on behind the scenes? If the .EndEdit() "applies changes to the underlying data source" why isn't it enough to apply those changes?
It is enough to "apply those changes"... to the data source. The data source is a DataTable
, which is an object in your application. The UpdateAll
call is what saves the changes from that DataTable
- in fact, all DataTables
in your DataSet
- to the database.
ADO.NET is based on a disconnected model. That means that your application is not directly connected to your database. Using ADO in VB6, changes you made to a Recordset
were made directly to the database. Not so in ADO.NET. When you call Fill
, a connection to the database is opened, data is copied from the database into a DataTable
and then the connection is closed. Any changes you make locally affect only that local copy. When you call Update
or UpdateAll
, the connection is opened again and the local changes saved to the database.