Click here to Skip to main content
15,912,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
string query = "SELECT medicine_name FROM medicines WHERE medicine_name like '" + clientName + "%'";


the above is the query i am using,but my problem is i want to show the user the related dats only after they type 3 or 4 character..but this statement will simply show even if they type single character..so pls help me,i tried in google i didnt find any solution...i am really looking for your solutions

thanks
in advance
velu
Posted
Updated 25-Sep-11 21:22pm
v2

Check the length of input in button click

that means in button click event
write as follows

if(txtinput.text.length>2)
{
  //code to get details
}
else
{
   //alert a message that you need to give minimum of 3 letters

}
 
Share this answer
 
v2
Comments
Iam Velu 26-Sep-11 2:37am    
NO i want to do it in query itself..not like programatically..is there any way for doing this?is tat possible?
P.Salini 26-Sep-11 2:56am    
if user did not enter 3 letters then what you want to display
P.Salini 26-Sep-11 3:02am    
Up to my knowledge i dont think its possible.
If possible i wish to know the answer
Arun Kumar K S 26-Sep-11 3:21am    
You r rt...,my up vote to you
I think the first solution gives the most flexibility, but if you really want it in SQL you could just add a string length condition. The following statement will only return results when clientName contains more than 3 characters. Note that the LENGTH function is dependent on the DB you are using.

SQL
string query = "SELECT medicine_name FROM medicines WHERE medicine_name like '" + clientName + "%' AND LENGTH('" + clientName + "') < 4)";
 
Share this answer
 
you may wanna try this one out but this is not the effecient code:

Declare @myValue as varchar(100);
Set @myValue = 'mySearch';	--replace this one the value you wanna search

IF Len(@myValue) >= 3
Begin
	Select * from table where column like @myValue + '%';
End

Else
Begin
	Select ''
End
 
Share this answer
 

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