如何使用LINQ搜索删除了某行的数据表? [英] How to use LINQ for searching a datatable with some row deleted?

查看:61
本文介绍了如何使用LINQ搜索删除了某行的数据表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据tabel,我想在其中查找任何重复的记录(例如,手机号码).我在LINQ中使用以下代码:

I have a datatabel, in which I want to find any duplicated record(for example, the mobile phone number). I use following code in LINQ:

var list_mobile = dataTable_QueryResult.Rows.OfType<DataRow>().Select(x => x["mobile"].ToString());
var q_mobile = from x in list_mobile
           group x by x into g
           let count = g.Count()
           orderby count descending
           select new { Value = g.Key, Count = count };

foreach (var x in q_mobile)
{
    if (x.Count > 1)
    {
        Label_Alarm.Visible = true;
    }
}



删除某些行时出现错误-访问已删除的行.我想使用Where()命令排除那些已删除的行,但是我不知道如何在LINQ中对其进行编码?有人可以帮我吗?谢谢!



It comes an error when some rows have been deleted - visiting the row that has been deleted. I want to use the Where() command to exclude those deleted rows, but I don''t know how to code it in LINQ? Could anyone help me this ? Thanks!

推荐答案



我认为RowState在这种情况下应该可以工作,

请尝试以下代码,
Hi,

I think RowState should work in this case,

Please try below code,
dataTable_QueryResult.Rows.OfType<datarow>().Where(s => s.RowState != DataRowState.Deleted).Select(x => x["mobile"].ToString());</datarow>



让我知道它是否对您不起作用,尽管我还没有尝试过.

谢谢



Let me know if it is not working for you, although i have not tried yet.

thanks


这篇关于如何使用LINQ搜索删除了某行的数据表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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