如何在C#中创建代码以执行此查询。 [英] How to create a code in C# for performing this query.
问题描述
Select *from Item where ItemName like '%plastic%hole%....%...%'
Select *from Item where ItemName like '%plastic%hole%' and ItemName like '%Button%'and ItemName like '....'
基本上我想搜索文字:
BUTTON PLASTIC 10MM过滤器2HOLE
塑料孔应该搜索当我搜索Hole Plastic 10MM然后应该工作因为se数据可以在上面的文字中找到。
我尝试过:
我正在尝试sql外卡,但不知道如何在c#logic中实现。
Basically I want to search text:
BUTTON PLASTIC 10MM FILTER 2HOLE
Plastic Hole should search When i search Hole Plastic 10MM then should work because data is found on the above text.
What I have tried:
I am trying sql wild card but not idea how will do implementing in c# logic.
推荐答案
正如我昨天在你问到这个时所说的那样:如何创建搜索开始或结束或任何数据匹配之间在太空&在第一个单词之前或结束任何搜索应该工作之前。 [ ^ ]
基本上,您需要为每个单词生成一个单独的WHERE条件:
As I told you when you asked this yesterday: How to create a search start or ending or between any data match after space & before after first word or ending whatever search should be work.[^]
Basically, you need to produce a separate WHERE condition for each word you want:
... WHERE myColumn LIKE '%Button% OR myColumn LIKE '%10MM%' OR ...
将查找包含任何单词的所有行。
另一种解决方案是使用全文搜索,但设置和使用起来更复杂:全文搜索 [ ^ ]
这样做我n C#与在C#中执行任何SQL查询完全相同:
Will find all rows which contain any of the words.
The other solution would be to use a full text search, but they are more complex to set up and use: Full-Text Search[^]
To do this in C# is exactly the same as doing any SQL query in C#:
using (SqlConnection con = new SqlConnection(strConnect))
{
con.Open();
using (SqlDataAdapter da = new SqlDataAdapter("SELECT MyColumn1, MyColumn2 FROM Item WHERE ItemName LIKE '%' + @W1 + '%' OR ItemName LIKE '%' + @W2 + '%'", con))
{
da.SelectCommand.Parameters.AddWithValue("@W1", "Button");
da.SelectCommand.Parameters.AddWithValue("@W2", "Hole");
DataTable dt = new DataTable();
da.Fill(dt);
...
}
}
这篇关于如何在C#中创建代码以执行此查询。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!