日期:2014-05-20 浏览次数:20812 次
DataTable dt = new DataTable(); dt.Columns.Add("a"); dt.Columns.Add("b"); dt.Columns.Add("c"); dt.Columns.Add("d"); dt.LoadDataRow(new object[] { "qq", "ss", "dd", "fg" },false); dt.LoadDataRow(new object[] { "qq", "ss", "dd", "reb" }, false); dt.LoadDataRow(new object[] { "qq", "acd", "dd", "tbg" }, false); var res = dt.AsEnumerable().GroupBy(p => p["a"].ToString() + p["b"].ToString() + p["c"].ToString());
------解决方案--------------------
void Main() { DataTable dt = new DataTable(); dt.Columns.Add("a"); dt.Columns.Add("b"); dt.Columns.Add("c"); dt.Columns.Add("d"); dt.LoadDataRow(new object[] { "qq", "ss", "dd", "fg" },false); dt.LoadDataRow(new object[] { "qq", "ss", "dd", "reb" }, false); dt.LoadDataRow(new object[] { "qq", "acd", "dd", "tbg" }, false); var query= dt.AsEnumerable().GroupBy(d=> new {a=d.Field<string>("a"),b=d.Field<string>("b"),c=d.Field<string>("c")}) .Where(g=>g.Count()>1); Console.WriteLine(query.Count()>0?"有重复":"无重复"); }
------解决方案--------------------
代码类似,只不过你这是字符串
参考http://topic.csdn.net/u/20120412/15/b36be23a-c01e-49b3-a011-3ca1b2acc68b.html
------解决方案--------------------
DataTable dt = new DataTable("test"); dt.Columns.Add(new DataColumn("a", typeof(string))); dt.Columns.Add(new DataColumn("b", typeof(string))); dt.Columns.Add(new DataColumn("c", typeof(string))); dt.Columns.Add(new DataColumn("d", typeof(string))); dt.Rows.Add("qq", "ss", "dd", "fg"); dt.Rows.Add("qq", "ss", "dd", "reb"); dt.Rows.Add("qq", "acd", "dd", "fg"); var result = dt.AsEnumerable().GroupBy(r => new { a = r["a"].ToString(), b = r["b"].ToString(), c = r["c"].ToString() }).Where(g => g.Count() > 1).Count() > 0; Console.WriteLine("result: " + result.ToString()); Console.ReadKey();
------解决方案--------------------
DataTable dt = new DataTable();
dt.Columns.Add("a",typeof(string));
dt.Columns.Add("b",typeof(string));
dt.Columns.Add("c",typeof(string));
dt.Columns.Add("d",typeof(string));
dt.LoadDataRow(new object[] { "qq", "ss", "dd", "fg" }, false);