XMLTemp

xiaoxiao2021-03-06  78

// Create a DataSet with one table and two columns DataSet OriginalDataSet = new DataSet ( "myDataSet");. OriginalDataSet.Namespace = "NetFrameWork"; DataTable myTable = new DataTable ( "myTable"); DataColumn c1 = new DataColumn ( "id ", Type.gettype (" system.int32 ")); c1.autoincrement = true; datacolumn c2 = new Datacolumn (" item "); myTable.columns.add (c1); myTable.columns.add (C2); OriginalDataSet .Tables.add (myTable); // Add Ten rows. DataRow newrow; for (int i = 0; i <10; i ) {newrow = myTable.neWRow (); newrow ["item"] = "item" I; MyTable.Rows.Add (new);} OriginalDataSet.Acceptchanges (); // Print Out Values ​​of Each Table In The Dataset Using the // Function Defined Below. PrintVales (Original Dataset "); // Write the XML schema and data to file with FileStream string xmlFilename = "myXmlDocument.xml";. // Create FileStream System.IO.FileStream fsWriteXml = new System.IO.FileStream (xmlFilename, System.IO.F ileMode.Create); // Create an XmlTextWriter to write the file System.Xml.XmlTextWriter xmlWriter = new System.Xml.XmlTextWriter (fsWriteXml, System.Text.Encoding.Unicode);. // Use WriteXml to write the document OriginalDataSet. .Writexml; // close the filestream. Fswritexml.close (); // dispose of the original dataset. OriginalDataSet.dispose (); // create a new dataset. Dataset newDataSet = New DataSet ("new dataset") ; // read the xml document back in. // Create new filestream to read schema with. System.io.filestream fsreadXML =

new System.IO.FileStream (xmlFilename, System.IO.FileMode.Open); // Create an XmlTextReader to read the file System.Xml.XmlTextReader myXmlReader = new System.Xml.XmlTextReader (fsReadXml);. // Read the XML document into the DataSet newDataSet.ReadXml (myXmlReader);. // Close the XmlTextReader myXmlReader.Close ();. // Print out values ​​of each table in the DataSet using the // function defined below printValues ​​(newDataSet, "New DataSet" }

Private Void PrintValues ​​("/ n" label) ("TABLENAME: T.TABLENAME) (" TABLENAME: T.TABLENAME); Foreach (DataRow); Foreach (Datarow R in T.ROWS) {Foreach (Datacolumn C in T.Columns) {Console.Write ("/ t" r [c]);} console.writeLine ();}}}

转载请注明原文地址:https://www.9cbs.com/read-94156.html

New Post(0)