Click here to Skip to main content
16,012,025 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
SELECT [dwords] FROM [meaning] WHERE (([dwords] ='" & TextBox1.Text & "') AND ([dcat] = '" & RadioButtonList1.Text & "' ))

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..
Posted
Updated 30-Sep-11 4:50am
v2

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:
VB
TextBox1.Text.PadRight(3, " ").Substring(0, 3).Trim


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 & "%"
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.
 
Share this answer
 
Comments
kwhiterosek 30-Sep-11 13:25pm    
hi. i dont understand what u mentioned last to research
Kschuler 30-Sep-11 13:50pm    
You can find a lot of information on the subject if you google "SQL Injection Attacks". Or, here is a CP Article that would help:
http://www.codeproject.com/KB/database/SqlInjectionAttacks.aspx
It even has a section that talks about parameters as a solution.
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
 
Share this answer
 
Comments
kwhiterosek 30-Sep-11 13:14pm    
ok. now i have a confusion of where to place that like keyword. i have placed textbox and radiobutton in where clause. so i need to know where andhow to use that Like-Limit and order by keywords.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900