Save Using .Accept Changes

Eduardo Lorenzo

Well-known member
Joined
Jun 27, 2006
Messages
86
He Everybody.

This is the first time I am going to use VS.Net (2003) to create a simple app with data, using MSAccess as the back-end and used drag-and-drop with the data objects.
I created the project. Dropped-in a TABLE I found in the Server Explorer, follow the wizard.
Fill a datatable with the OleDBDataAdapter object. Add a DataGrid, set the DataSource property to the Datatable(using code).

Now I add the "Save Button", how would I go about saving the changes typed into the DataGrid?

All inputs will be greatly appreciated.
 
Youll be wanting to look at the DataAdapter class. The DataAdapter is the piece that goes between the DataSet and the DataBase. The DataAdapter is meant to be easy to use, supporting the 4 main DB commands: SelectCommand, InsertCommand, UpdateCommand and DeleteCommand. Theres even support for it to build all of those commands for you (such as basic SELECT, INSERT, etc. SQL statements) assuming you dont have any reserved words for table or column names.

Youll end up calling an "Update" method on the DataAdapter, which will send the updates in your DataSet to the database (Access in your case). Each row in the DataSet has a "rowstate", such as "Unmodified", "Modified", "Deleted", etc. Its that rowstate that determines which command the DataAdapter will run. So if youve modified 1 row then the DataAdapter would call the UpdateCommand 1 time.

After you call the Update method, youll generally call AcceptChanges on the DataSet. Its probably worthwhile to find an article (or a set of them) or a book on the basic flow, to outline the "Whys" of the DataAdapter and DataSet.AcceptChanges and other things Im leaving out.

-ner
 
Back
Top