选择具有重复值的数据表的所有记录 [英] Select all records of a datatable with duplicate values

查看:75
本文介绍了选择具有重复值的数据表的所有记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何从数据表中选择特定年份(例如2014年)的所有记录,其中列值之一(此处为2014年)在数据的多行中重复 linq或C#中的任何其他方法创建表格.

How do we select all the record of particular year (e.g. 2014) from a datatable where one of the column value(here 2014) is repeated on multiple rows of table using linq or any other method in C#.

这是数据表:

推荐答案

如果您要检索2014年的所有记录,请使用以下linq查询,IT会检查您的数据列中是否有数据,我是肯定会有用..

If you are trying to retrieve all the records lies on the Year 2014, use following linq query,IT will check your data column has data or not, I am sure it will works..

        //selecting all the records of 2014
        IEnumerable<DataRow> dtrow = default(IEnumerable<DataRow>);
        dtrow = yourtable.AsEnumerable().Where(x => x.Field<Int64>("year") == Convert.ToInt64("2014"));
        if (dtrow.Count() > 0)
        {
            dataTbl = dtrow.CopyToDataTable(); //dataTbl is the DataTable
        }

这篇关于选择具有重复值的数据表的所有记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆