在数据表中查找值 [英] Find a value in DataTable

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

问题描述

有没有办法在C#中不用逐行操作就可以在DataTable中找到一个值?

Is there a way to find a value in DataTable in C# without doing row-by-row operation?

该值可以是数据表中单元格(row[columnName].value 的子字符串,以逗号分隔)的一部分,并且该值可以出现在行中的任何一列中.

The value can be a part of (a substring of row[columnName].value , separated by comma) a cell in the datatable and the value may be present in any one of columns in the row.

推荐答案

DataTable 或 DataSet 对象将有一个 Select 方法,该方法将根据作为参数传入的查询返回结果的 DataRow 数组.

A DataTable or DataSet object will have a Select Method that will return a DataRow array of results based on the query passed in as it's parameter.

根据您的要求,您的过滤器表达式必须具有一定的通用性才能使这项工作正常进行.

Looking at your requirement your filterexpression will have to be somewhat general to make this work.

myDataTable.Select("columnName1 like '%" + value + "%'");

这篇关于在数据表中查找值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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