The operation of the dataset on XML. WriteXml () and ReadXml. DataSet. AcceptChanges (). DataSet. DIspose (). Freeing resources

Source: Internet
Author: User

Private voidDemonstratereadwritexmldocumentwithstreamreader () {//Create a DataSet with one table and both columns.DataSet Originaldataset =NewDataSet ("DataSet"); Originaldataset.namespace="NETFramework"; DataTable Table=NewDataTable ("Table"); DataColumn Idcolumn=NewDataColumn ("ID", Type.GetType ("System.Int32")); Idcolumn.autoincrement=true; DataColumn Itemcolumn=NewDataColumn ("Item"); Table.    Columns.Add (Idcolumn); Table.    Columns.Add (Itemcolumn);    ORIGINALDATASET.TABLES.ADD (table); //Add ten rows.DataRow NewRow;  for(inti =0; I <Ten; i++) {NewRow=table.        NewRow (); newrow["Item"]="Item"+i; Table.    Rows.Add (NewRow);    } originaldataset.acceptchanges (); //Print out values of all table in the DataSet//using the function defined below.Printvalues (Originaldataset,"Original DataSet"); //Write the schema and data to an XML file.    stringXMLfileName ="Xmldocument.xml"; //Use WriteXml to write the document.Originaldataset.writexml (XMLfileName); //Dispose of the original DataSet.Originaldataset.dispose (); //Create a new DataSet.DataSet NewDataSet =NewDataSet ("New DataSet"); //Read the XML document into the DataSet.Newdataset.readxml (XMLfileName); //Print out values of all table in the DataSet//using the function defined below.Printvalues (NewDataSet,"New DataSet");}Private voidPrintvalues (DataSet DataSet,stringlabel) {Console.WriteLine ("\ n"+label); foreach(DataTable tableinchdataset.tables) {Console.WriteLine ("TableName:"+table.        TableName); foreach(DataRow rowinchtable. Rows) {foreach(DataColumn columninchtable. Columns) {Console.Write ("\table"+Row[column]);        } Console.WriteLine (); }    }}

The operation of the dataset on XML. WriteXml () and ReadXml. DataSet. AcceptChanges (). DataSet. DIspose (). Freeing resources

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.