选择查询以结合LIKE运算符和ORDER BY关键字 [英] select query to combine LIKE operator and ORDER BY keyword

查看:134
本文介绍了选择查询以结合LIKE运算符和ORDER BY关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SELECT [dwords] FROM [meaning] WHERE (([dwords] ='" & TextBox1.Text & "') AND ([dcat] = '" & RadioButtonList1.Text & "' ))


在此查询中,我想为文本框值的3个字符添加like运算符,并按字母顺序进行排序.


In this query, I want to add the like operator for 3 character of a textbox value and order by in alphabetical order.
somebody rewrite this and help me..

推荐答案

听起来您已经有了所需的东西……只需将它们放在一起即可.

如果只需要文本框的前三个字符,则可以使用padright和子字符串,如下所示:
It sounds like you already have what you need...just put it together.

If you want just the first three characters of a textbox you could use padright and substring like this:
TextBox1.Text.PadRight(3, " ").Substring(0, 3).Trim



这样,即使用户仅输入单个字符,您的代码也可以使用.

另外,当您使用Like关键字时,可以在字符串中使用%作为通配符.因此,您还想将其添加到您的字符串中.



This way even if the user only typed in single character your code will work.

Also, when you use the Like keyword you use % inside the string as a wildcard character. So you''d want to also add that to your string.

TextBox1.Text.PadRight(3, " ").Substring(0, 3).Trim & "%"

或结尾和开头,如果要包含文本而不是仅以文本开头的[dword],则为

.

如果要按某种顺序订购,只需在末尾添加Order By子句. Order By [dwords]

请参阅本文 [ google [

or to both the end and the start if you want any [dword] that contains the text instead of just starts with it.

If you want to order by something you just need to add the Order By clause at the end. Order By [dwords]

See this article[^] for more info about Order By.

I''d also like to point out that your code is vulnerable to SQL injection attacks. You should be using parameters instead of text right from the textbox. You could start researching that with google[^].

Hope this helps.


以下是要执行的步骤.

1)此链接将带给您Substring的概念,以获取文本框的3个字符".
http://msdn.microsoft.com/en-us/library/aka44szs.aspx

2)此链接将使您了解如何使用SQL的赞"运算符.
http://msdn.microsoft.com/en-us/library/ms179859.aspx

3)该链接将使您想到订购依据"条款.
http://www.w3schools.com/sql/sql_orderby.asp
Here are steps to follow.

1) This link will give you idea of Substring, to get "3 character of a textbox".
http://msdn.microsoft.com/en-us/library/aka44szs.aspx

2) This link will give you idea of, How to use "Like" Operator of SQL.
http://msdn.microsoft.com/en-us/library/ms179859.aspx

3) This link will give you idea of, "Order By" Clause.
http://www.w3schools.com/sql/sql_orderby.asp


这篇关于选择查询以结合LIKE运算符和ORDER BY关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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