tailieunhanh - Creating an XML File That Shows Changes Made to a DataSet

[ Team LiB ] Recipe Creating an XML File That Shows Changes Made to a DataSet Problem When you use the GetXML( ) method of the DataSet, you may see only the current values in the DataSet. You want to get the original values and see which rows were added, edited, or deleted. Solution Create an XML DiffGram | Team LiB Recipe Creating an XML File That Shows Changes Made to a DataSet Problem When you use the GetXML method of the DataSet you may see only the current values in the DataSet. You want to get the original values and see which rows were added edited or deleted. Solution Create an XML DiffGram which is a document that details the modifications made to a DataSet. The sample code contains two event handlers and a single method Sets up the sample by loading the Categories table from Northwind into a DataSet and displays the DiffGram for the DataSet before modification. Make Changes Deletes the first row modifies the second row inserts a row before the first row and adds a row to the end of the Categories DataTable DisplayDiffGram This method outputs the DiffGram for the DataSet to both a file and to a textbox on the form. The C code is shown in Example 8-12. Example 8-12. File Namespaces variables and constants using System using using using using using using using Table name constants private const String CATEGORIES_TABLE Categories Field name constants private const String CATEGORYNAME_FIELD CategoryName private const String XMLDIFFGRAMFILENAME Temp_Directory private DataSet ds . . . private void XmlDiffgramForm_Load object sender e Select fields from Categories table without the Picture BLOB. String sqlText SELECT CategorylD CategoryName Description FROM Categories Load the Categories table into the DataSet. SqlDataAdapter da new SqlDataAdapter sqlText S ql_ConnectString ds new DataSet ds Categories DisplayDiffGram private void makeChangesButton_Click object sender e Disable the make changes button. false DataTable dt Categories Delete the first .