如何在没有循环的情况下检查特定数据列是否包含给定值

问题描述:


如何检查特定数据列是否包含给定值而没有循环,来自数据表的数据列,


How to i check particular datacolumn contains given value with out looping, datacolumn from a datatable,

使用DataTableSelect(String expression)方法.此方法返回DataRow s(DataRow[])的数组.因此,您要做的就是检查所返回数组的Length属性是否大于零,并完成操作.

这是MSDN参考: http://msdn.microsoft.com/zh-cn/library/det4aw50%28v = VS.90%29.aspx [
Use DataTable''s Select(String expression) method. This method returns an array of DataRows (DataRow[]). So all you have to do is to check if the Length 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);