怎么读取DataTable某一列的值?然后用c#代码判断是否有重复数据?linq还是怎么做呢? 假设你上图表格数据为 datatable dt,列分别为aa,bb,cc,ddvar query=from p in dt.asenumerable()/分组 group p by new { t1=p.field(\"aa\").tostring().substring(0,p。.
怎么读取DataTable某一列的值?然后用c#代码判断是否有重复数据?linq还是怎么做呢? public static void cs(){System.Data.DataTable dt=new System.Data.DataTable();dt.Rows.Add(\"\");var quer=from tb in dt.AsEnumerable()group tb by tb.Field(\"xx\")into xselect new{a=x.Key,b=x};foreach(var c in quer){int i=0;foreach(var d in c.b){i+;}if(i>;1){有重复}}for(int i=0;i;i+){var qu=from tb in dt.AsEnumerable()where tb.Field(\"xx\")=dt.Rows[i][\"xx\"].ToString()select tb;if(qu.Count()>;1){有重复}}}两种方法 看你喜欢哪种
LINQ怎么根据“某个字段”去除重复数据查询(急求答案) Distinct方法的第二重载可以Enumerable.Distinct(IEnumerable,IEqualityComparer),例如数据类为class School{public int Id { get;set;}public string Name { get;set;}是否重点学校public bool IsKeySchool { get;set;}}实现IEqualityComparer的比较器类为class SchoolComparer:EqualityComparer{public override bool Equals(School x,School y){return x.IsKeySchool=y.IsKeySchool;}public override int GetHashCode(School obj){return obj.IsKeySchool.GetHashCode();}}原始列表为var schoolList=new List<;School>;{new School{Id=1,Name=\"三中\",IsKeySchool=true},new School{Id=2,Name=\"五中\",IsKeySchool=true},new School{Id=3,Name=\"十中\",IsKeySchool=false},new School{Id=4,Name=\"十五中\",IsKeySchool=true},new School{Id=5,Name=\"二十中\",IsKeySchool=false},};执行var tempList=schoolList.Distinct(new SchoolComparer());结果就只有两条“三中”和“十中”
linq 如何插入多条重复数据 protected void btnAdd_Click(object sender,EventArgs e){ using(var db=new myDataClassesDataContext()){ var q=(from o in db.UserTable select o.UserName.toarry();if。q.contains(txtUserName.Text)){ UserTable u=new UserTable();u.UserName=txtUserName.Text;u.UserPwd=txtUserPwd.Text;u.UserRight=DpLUserRight.Text;} } }
linq 怎么得到某数据集里相同的字段个数