Managing database deletions?
-
I hope I can explain the problem clear enough. I am loading data from my database into a DataSet and then display the data in a ListView. The user can then select one or more of the records in the ListView for deletion and the click the Delete button. After the Update method of the DataAdapter was called, I would like the records that were successfully deleted, to be removed from the ListView, but the records that could not be deleted (for whatever reason: Concurrence problems, has child records, etc) to be highlighted in the ListView. The user can then click on a Report button to see what the reason was for each of the delete errors. Is this possible? How can this be achieved? I am using Visual Studio 2003 and C#. Thanks. Kobus
-
I hope I can explain the problem clear enough. I am loading data from my database into a DataSet and then display the data in a ListView. The user can then select one or more of the records in the ListView for deletion and the click the Delete button. After the Update method of the DataAdapter was called, I would like the records that were successfully deleted, to be removed from the ListView, but the records that could not be deleted (for whatever reason: Concurrence problems, has child records, etc) to be highlighted in the ListView. The user can then click on a Report button to see what the reason was for each of the delete errors. Is this possible? How can this be achieved? I am using Visual Studio 2003 and C#. Thanks. Kobus
First you have to save the records to be deleted for later highlighting them. Save them to a dataset or whatever you find yourself comfortable with. Then when deleting the rows use try catch error handling. I hope you know how to use try catch stuff. Whatever. Then in the catch part if there are any errors you can your saved datas there and highlight the previously them.