如何在没有循环的情况下检查特定数据列是否包含给定值 [英] How to check particular datacolumn contains given value with out looping
本文介绍了如何在没有循环的情况下检查特定数据列是否包含给定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查特定数据列是否包含给定值而没有循环,来自数据表的数据列,
How to i check particular datacolumn contains given value with out looping, datacolumn from a datatable,
推荐答案
使用DataTable
的Select(String expression)
方法.此方法返回DataRow
s(DataRow[]
)的数组.因此,您要做的就是检查所返回数组的Length
属性是否大于零,并完成操作.
这是MSDN参考: http://msdn.microsoft.com/zh-cn/library/det4aw50%28v = VS.90%29.aspx [
UseDataTable
''sSelect(String expression)
method. This method returns an array ofDataRow
s (DataRow[]
). So all you have to do is to check if theLength
property of said returned array is greater than zero and your done.
Here is the MSDN reference: http://msdn.microsoft.com/en-us/library/det4aw50%28v=VS.90%29.aspx[^].
Best Regards,
—MRB
您确实不能...您可以编写影响where子句的LINQ代码来过滤它,即使您不是.循环IT是.循环是编程中一个基本的,几乎不可避免的前景.如果您正在寻找魔术,恐怕您将不得不继续寻找.
You really can''t... You can write LINQ code that effects a where clause to filter it, but even if YOU aren''t looping IT is. Loops are a basic, nearly inescapable prospect in programming. If you''re looking for magic, I''m afraid you''ll have to keep looking.
var rowsWithTheValue = myTable.Rows.Where(a => a["Column"] == value);
这篇关于如何在没有循环的情况下检查特定数据列是否包含给定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文