使用csharp在sqlserver中搜索查询 [英] Search query in sqlserver using csharp

查看:105
本文介绍了使用csharp在sqlserver中搜索查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

在表中有一个关键字列,其值是"school".当我在文本框中写学校"并搜索与此记录相关的所有列时,都显示在gridview中.但是当我写学校"时,它不显示任何记录

Hi all,

In a table there is a keyword column whose values is "school". When I write "school" in textbox and search all columns related to this record are shown in gridview.But when I write "the school" it donot show any record

str = "select id from school  where keyword like ''%" + TextBox1.Text + "%''";



查询内容是什么?

谢谢



What will be the query?

Thanks

推荐答案

是否有关键字为"the school"的记录?如果没有,那就是为什么没有结果的答案.
Is there a record with a keyword of "the school"? If not, then that is your answer as to why there is no result.




您的查询是正确的.根本没有问题.由于文本框值的修整,结果可能不会出现.

请同时在调试模式下检查命令字符串,您的查询究竟是什么样子.

应该是
Hi,

Your query is right. there is no problem at all. result may not be come because of trimming of the textbox value.

please also check your commandstring in debug mode, what exactly your query look like.

It should be
select id from school  where keyword like '%school%'


如果我正确理解了您的问题,您就误解了like关键字.它从较大的字符串中搜索字符串的一部分.例如,句子:
If I understood your question correctly, you''ve misunderstood the like keyword. It searches a portion of a string from a larger string. For example for sentence:
The school is over

发现%school%会匹配,但是如果文本是

finding %school% would match, but if the text is

School

,然后搜索%The school%将不匹配,因为它没有出现在文本中

then searching for %The school% won''t match since it doesn''t appear in the text


这篇关于使用csharp在sqlserver中搜索查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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