Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 22nd, 2010  |  syntax: C#  |  size: 0.70 KB  |  views: 66  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.   DataSet ds = new DataSet();
  2.             ds.ReadXml(@"D:\foo.xml");
  3.             DataTable tbl =ds.Tables["cj"];
  4.            
  5.             tbl.PrimaryKey = new DataColumn[] { tbl.Columns["a"] };
  6.             DataView view = tbl.DefaultView;
  7.            
  8.             view.Sort = "a ASC";
  9.  
  10.             DataTable sortedBy_a = view.ToTable();
  11.  
  12.             //remove all the CJ tables -- they're currently unsorted
  13.             ds.Tables.Remove("cj");
  14.  
  15.             //add in all the sorted CJ tables
  16.             ds.Tables.Add(sortedBy_a);
  17.  
  18.             StringWriter sw = new StringWriter();
  19.            
  20.            ds.WriteXml(sw);
  21.            Console.WriteLine(sw.ToString());
  22.            Console.ReadLine();