标签:
最一般的用法
1 var rows = 2 from c in dataTrue.AsEnumerable() 3 from t in dataPre.AsEnumerable() 4 where t[0].ToString().StartsWith(c[1].ToString()) 5 select new 6 { 7 ID = c[0], 8 dayTime = this.StrDateConvertDateToString(c[1].ToString()), 9 10 value = c[2], 11 pre1 = t[1], 12 pre2 = t[2], 13 pre3 = t[3], 14 15 valueu = c[3], 16 pre1u = t[4], 17 pre2u = t[5], 18 pre3u = t[6], 19 20 valuem = c[4], 21 pre1m = t[7], 22 pre2m = t[8], 23 pre3m = t[9], 24 25 valuec = c[5], 26 pre1c = t[10], 27 pre2c = t[11], 28 pre3c = t[12] 29 }; 30 rows = rows.Distinct(); 31 32 // rows = rows.Distinct(); 33 34 35 DataTable dt = new DataTable(); 36 dt.Columns.Add("ID", typeof(string)); 37 dt.Columns.Add("dayTime", typeof(string)); 38 dt.Columns.Add("value", typeof(string)); 39 dt.Columns.Add("pre1", typeof(string)); 40 dt.Columns.Add("pre2", typeof(string)); 41 dt.Columns.Add("pre3", typeof(string)); 42 43 44 dt.Columns.Add("valueu", typeof(string)); 45 dt.Columns.Add("pre1u", typeof(string)); 46 dt.Columns.Add("pre2u", typeof(string)); 47 dt.Columns.Add("pre3u", typeof(string)); 48 49 50 dt.Columns.Add("valuem", typeof(string)); 51 dt.Columns.Add("pre1m", typeof(string)); 52 dt.Columns.Add("pre2m", typeof(string)); 53 dt.Columns.Add("pre3m", typeof(string)); 54 55 56 57 dt.Columns.Add("valuec", typeof(string)); 58 dt.Columns.Add("pre1c", typeof(string)); 59 dt.Columns.Add("pre2c", typeof(string)); 60 dt.Columns.Add("pre3c", typeof(string)); 61 //插入id 62 rows.ToList().ForEach(kv => dt.Rows.Add(kv.ID, kv.dayTime, kv.value, kv.pre1, kv.pre2, kv.pre3, kv.valueu, kv.pre1u, kv.pre2u, kv.pre3u, kv.valuem, kv.pre1m, kv.pre2m, kv.pre3m, kv.valuec, kv.pre1c, kv.pre2c, kv.pre3c)); 63 64 65 this.dg1.DataContext = null; 66 this.dg1.DataContext = dt; 67 this.dg1.Items.Refresh();
标签:
原文地址:http://www.cnblogs.com/billly/p/5365047.html