All this staff is handled for you by DataAdapter and DataSets.
If you bind a datagrid to datasource whenever you edit the grid the changes are transmitted back to the database.