Mega Code Archive

 
Categories / C# / ADO Database
 

Open the XML file and read into a DataSet

using System; using System.IO; using System.Data; public class MainClass {     static void Main(string[] args) {         if (args.Length != 1)             return;         FileStream fs = new FileStream(args[0], FileMode.Open);         DataSet ds = new DataSet();         ds.ReadXml(fs);         // Use a DataTable to display the members.         DataTable mt = ds.Tables["member"];         for (int row = 0; row < mt.Rows.Count; row++) {             for (int col = 0; col < mt.Columns.Count - 1; col++) {                 Console.WriteLine("{0,-10}{1}",                     mt.Columns[col].Caption,                     mt.Rows[row][col].ToString().Trim());             }             Console.WriteLine();         }         fs.Close();     } }