Eduardo Lorenzo Posted March 24, 2007 Posted March 24, 2007 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. Quote
*Experts* Nerseus Posted March 25, 2007 *Experts* Posted March 25, 2007 You'll 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. There's even support for it to build all of those commands for you (such as basic SELECT, INSERT, etc. SQL statements) assuming you don't have any reserved words for table or column names. You'll 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. It's that rowstate that determines which command the DataAdapter will run. So if you've modified 1 row then the DataAdapter would call the UpdateCommand 1 time. After you call the Update method, you'll generally call AcceptChanges on the DataSet. It's probably worthwhile to find an article (or a set of them) or a book on the basic flow, to outline the "Why's" of the DataAdapter and DataSet.AcceptChanges and other things I'm leaving out. -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.