using System; using System.Data; namespace DelegateTest { public class Program { public static void Main(string[] args) { DataTable dt = new DataTable(); dt.Columns.Add("ID",typeof(string)); dt.Columns.Add("Name",typeof(string)); DataRow dr1 = dt.NewRow(); dr1[0] = "1001"; dr1[1] = "张三"; dt.Rows.Add(dr1); DataRow dr2 = dt.NewRow(); dr2[0] = "1001"; dr2[1] = "张三"; dt.Rows.Add(dr2); foreach (DataRow dr in dt.Rows) { Console.WriteLine(dr[0]+"\t"+dr[1]); } Console.WriteLine("------------------------------------"); DataTable dt2 = dt.DefaultView.ToTable(true,"ID","Name"); foreach (DataRow dr in dt2.Rows) { Console.WriteLine(dr[0] + "\t" + dr[1]); } } } }