I've got a grid that I'm applying a datasource to in code. I need to setup insert/update/delete commands. When I do one of these ops, which is the best event to attach the save code?
Thanks for the assist Mike. Sean, you are probably interested in calling AcceptChanges on the DataTable, explained in the DataAdapter doc above.
If the grid is bound to a DataTable, then the table will automatically be updated by the grid. You don't have to manually copy the data from the grid into the DataTable.
Typically, you would use a DataAdpater to get your data from the DataBase into the DataTable and to write the changes back to the DataBase from the DataTable. That part doesn't even involve the grid, so it's not something we document, but I'm sure there is documentation on the DataAdapter provided by Microsoft.
https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/updating-data-sources-with-dataadapters
Well, I only want to save what's in the row because I don't know any other way. Access the row, assign each cell a var, send the insert stmt to the DB.
How should I be doing it? Again, if you've got an example that shows what I should be doing I'd love to see it. I've looked all over and I can see all types of things that can be done, but nowhere that shows how to simply save a new/updated row to a DB.
AfterRowInsert will never show you the new data, because there is no new data at that point. This event fires as soon as the AddNew row is created. So that's before the user has had a change to change any values in the row.
If you want to retain what is in the add new row you can set grid.RowUpdateCancelAction = RowUpdateCancelAction.RetainDataAndActivation;