简体   繁体   中英

Word specific search in asp using c# for auto-complete

I have a column in sql called "Name", it has these values:

abhay kumar
rajesh saaw
anjan raj
gopal murti
pravat saha

Now I want sql code that will return only words containing "r".

So in this query, it should return:

kumar, rajesh, raj, murti, pravat

and not :

abhay, anjan, gopal, saha.

The SQL LIKE operator should do the job. You can compare against text pattern using the following SQL command form:

SELECT ... WHERE Name LIKE '%r%';

For example:

SELECT Name FROM Person WHERE Name LIKE '%r%';

The % is a wildcard that represents various count of various characters (similarly to * in filenames). So %r% means any string that contains the letter r .

我不确定如何在C#中连接数据,但是如果您使用linq,我将建议以下内容(尽管我对数据访问层做了很多假设):

ctx.User.All(u => u.Contains("r"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM