tailieunhanh - Accessing Deleted Rows in a DataTable

Accessing Deleted Rows in a DataTable Problem When you delete rows from a DataSet they are really marked for deletion until changes are committed by calling AcceptChanges( ) either directly or indirectly. | Team LiB Recipe Accessing Deleted Rows in a DataTable Problem When you delete rows from a DataSet they are really marked for deletion until changes are committed by calling AcceptChanges either directly or indirectly. You want to access the rows that you have deleted from a DataTable. Solution Use either a DataView or the Select method of the DataTable to access deleted rows. The sample code contains three event handlers Sets up the sample by creating a DataTable containing Orders data from Northwind. A view containing the Current rows is bound to a data grid on the form. Current Rows Sets the view of the Orders data to display only Current rows. The text box displaying information about deleted rows is cleared. Deleted Rows Sets the view of the Orders data to display only Deleted rows. The DataTable for the DataView is retrieved and the Select method is used to get the Deleted rows. The overloaded indexer in C or Item property in is used to retrieve the OrderlD from the Original version of these deleted rows. This information is displayed in the text box on the form. The C code is shown in Example 2-6. Example 2-6. File Namespaces variables and constants using System using using using using private DataView dv . . . private void AccessDataSetDeletedRowsForm_Load object sender e Fill the Orders table. SqlDataAdapter da new SqlDataAdapter SELECT FROM Orders S ql_ConnectString DataTable dt new DataTable Orders dt Define a view of just the Current rows. dv new DataView dt null null dv true private void currentRadioButton_CheckedChanged object sender e Filter to include only current rows. .