LINQ查询数据表以检查记录是否存在 [英] LINQ Query on Datatable to check if record exists

查看:697
本文介绍了LINQ查询数据表以检查记录是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对称为Records的数据表执行LINQ查询,并检查是否存在记录.如果存在,我想找出它所在的行.我该怎么做?

I want to perform a LINQ query on a datatable called Records and check if a record exists. If it exists, I want to find out the row which it is in. How might I go about doing this?

我想在添加system.linq命名空间后在数据表上执行一个.where,但是该方法似乎不存在.请指教

I wanted to do a .where on my datatable after adding the system.linq namespace but the method didnt seem to exist. Please advise

P.S:在2010年版中使用c#

P.S : Am using c# in vs 2010

推荐答案

您不能使用该方法,因为DataRowCollection没有实现IEnumerable<T>.您需要使用AsEnumerable()扩展名:

You cannot use the method because DataRowCollection doesn't implement IEnumerable<T>. You need to use the AsEnumerable() extension:

var dataRowQuery= myDataTable.AsEnumerable().Where(row => ...

您可能还需要一个对System.Data.DataSetExtensions的项目引用,才能正常工作.

You might also need a project reference to System.Data.DataSetExtensions for this to work.

祝你好运!

这篇关于LINQ查询数据表以检查记录是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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