datatable.select中单列的多个相似条件

编程入门 行业动态 更新时间:2024-10-10 19:20:58
本文介绍了datatable.select中单列的多个相似条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要从datatable中获取结果。选择此列包含长字符串的位置。 用户搜索多个一次条款。 例如 如果用户正在搜索注射Spine :: 我在列中有10,000行。 现在我需要显示与两个注入都匹配的行和脊椎。我不知道这两个词在这个字符串中的位置。 所以,我需要使用Like Condition。我不知道如何使用它。以下是用户的八个样本行数据应仅获得第一行和第二行,而其他所有行包含字符串注入,但不包括Spine。

Hi, I need to get results from a datatable.Select where this column contains long string. User searches with multiple terms at a time. For Example If user is searching as Injection Spine :: I am having 10,000 rows in a column. Now i need to show rows where it matches both Injection and Spine. I do not know where these 2 terms will be in that string. So, i need to use Like Condition. I am not sure how i can use it. Following are eight sample lines of data out of user should get only first line and second lines only while other all lines contains string Injection, but not Spine.

Injection/Aspiration of Spine, Diagnostic/Therapeutic Injection procedure, arterial, for occlusion of arteriovenous malformation, spine Injection, intralesional; up to and including 7 lesions Injection, intralesional; more than 7 lesions Subcutaneous injection of filling material (eg, collagen); 1 cc or less Subcutaneous injection of filling material (eg, collagen); 1.1 to 5.0 cc Subcutaneous injection of filling material (eg, collagen); 5.1 to 10.0 cc Subcutaneous injection of filling material (eg, collagen); over 10.0 cc Injection(s); single tendon origin/insertion

先谢谢。 我尝试过:

Thanks In advance. What I have tried:

DataRow[] ProRow = MainDS.Tables["Table1"].Select("LDesc Like '%" + SearchTerm + "%' And Active = 1 and Type in('CPT')");

推荐答案

您可以使用 Linq To DataSet [ ^ ]: You can use Linq To DataSet[^]: DataTable dt = MainDS.Tables["Table1"] var result = dt.AsEnumerable() .Where(x=>x.Field<string>("FieldName").Contains("Injection") && !x.Field<string>("FieldName").Contains("Spire")) .ToList();

以上查询应返回符合条件的DataRows列表。 有关详细信息,请参阅: LINQ to DataSet示例 [ ^ ] LINQ to DataSet中的查询 [ ^ ] 查询数据集(LINQ to DataSet) [ ^ ] 如果您无法使用Linq,则可以在数据库级别上过滤数据。为此,您应该使用 SqlCeCommand [ ^ ]和参数 [ ^ ]。要获得结果,请使用 ExecuteReader() [ ^ ]并将数据读入 SqlCeDataReader [ ^ ]。最后,使用 DataTable.Load() [ ^ ]获取数据的方法从 SqlCeDataReader 。 试试! 祝你好运!

Above query should return a list of DataRows which meet criteria. For further details, please see: LINQ to DataSet Examples[^] Queries in LINQ to DataSet[^] Querying DataSets (LINQ to DataSet)[^] If you can't use Linq, you can filter data on database level. To be able to do that, you should use SqlCeCommand[^] together with parameters[^]. To get results, use ExecuteReader()[^] and read data into SqlCeDataReader[^]. Finally, use DataTable.Load()[^] method to get data from SqlCeDataReader. Try! Good luck!

更多推荐

datatable.select中单列的多个相似条件

本文发布于:2023-11-11 05:19:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577487.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   条件   datatable   select

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!