日期:2014-05-17 浏览次数:20520 次
DataTable dt1 = new DataTable();
dt1.Columns.Add("id", typeof(Int32));
dt1.Columns.Add("name", typeof(String));
dt1.Columns.Add("age", typeof(Int32));
DataRow dr = null;
dr = dt1.NewRow();
dr["id"] = 1;
dr["name"] = "aa";
dr["age"] = 11;
dt1.Rows.Add(dr);
dr = dt1.NewRow();
dr["id"] = 2;
dr["name"] = "bb";
dr["age"] = 12;
dt1.Rows.Add(dr);
dr = dt1.NewRow();
dr["id"] = 3;
dr["name"] = "cc";
dr["age"] = 13;
dt1.Rows.Add(dr);
DataTable dt2 = new DataTable();
dt2.Columns.Add("name", typeof(String));
dt1.AsEnumerable().ToList().ForEach(x => dt2.Rows.Add(x.Field<string>("name")));
dt2.AsEnumerable().ToList().ForEach(x => Console.WriteLine(x.Field<string>("name")));//输出aa、bb、cc
select top 0 *