datatable.select中单列的多个相似条件 [英] Multiple like conditions on single column in datatable.select

查看:94
本文介绍了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中单列的多个相似条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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