Click here to Skip to main content
15,921,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Actually i am using search option in my form.in that by student name i am searching the records from student table for example u can see below.

//student table
VB
student_id  | Name | Class | Created_on
1001        |pavan | second |1/2/2013
1002        |pavani| first  |4/2/2013
1003        |siddu |third   |4/2/2013
1004        |suresh|third   |2/4/2013



now what i want is when i enter "pav" in my search-text-box i want to get first two records from the above table like below

VB
student_id  | Name | Class | Created_on
1001        |pavan | second |1/2/2013
1002        |pavani| first  |4/2/2013
Posted

select * from student where Name like '%pav%'
 
Share this answer
 
Comments
ntitish 28-Feb-13 3:20am    
instead of "pav" can i take any variable name ha sir....
ntitish 28-Feb-13 3:21am    
like select*from student where name like '%@name%' or student_id like '%@Student_id%'
[no name] 28-Feb-13 3:49am    
yes you can use any thing like the value of your textbox or anything. and I m sir not mam. :)
ntitish 28-Feb-13 3:27am    
sorry mam i not seen ur name properly .....can i write like above statement mam
ntitish 28-Feb-13 5:44am    
it is not working sir i written my code like below

select * from student_details where (child_name like '%@Student_ID%' or student_id like '%@Child_Name%') and School_Name=@School_Name
suppose if you are taking variable for name field as Sname and for student_id field as Sid then
string Sname="pav";
string Sid="01";

sql="select * from student_details where name like '%" + Sname.toString() + "%' or student_id like '%" + Sid.toString() + "%'";
 
Share this answer
 
Comments
ntitish 2-Mar-13 5:14am    
i am taking variables from asp.net and passing in sql server 2005.....the code u have given for front end coding na sir.....i need for sql server
ntitish 2-Mar-13 5:27am    
it is working but for this i have to write the full Child_Nam or registration_id of the student then only it is working
//this is asp.net code of my form
cmdSearch.Parameters.Add(new SqlParameter("@Student_ID", SqlDbType.VarChar, 50));
cmdSearch.Parameters["@Student_ID"].Value = txtSearch.Text;

cmdSearch.Parameters.Add(new SqlParameter("@Child_Name", SqlDbType.VarChar, 50));
cmdSearch.Parameters["@Child_Name"].Value = txtSearch.Text;

//this is the code for sql server
select * from student_details where (child_name like '%@Student_ID%' or student_id like '%@Child_Name%') and School_Name=@School_Name
[no name] 2-Mar-13 5:47am    
Your ASP.net code is correct but below these you have to write your query to search anything.
Dude this is the only query for front end, you have to write query in front end only if u want to display result. You want to write query in ASP.net then that's the query.
 
Share this answer
 
Comments
ntitish 2-Mar-13 6:08am    
sir i think so you are not getting my problem...it is my fault only..
ok i will explain u again.
i am having 5 students with names suresh,siddu,sai,snehal,mahesh
if i passed the @Student_ID=s means the first four names should be displayed...but my query is not giving that result .it is giving the result when ever i given a correct name like pavan means it is show ing the record of pavan...
below is my sqlquery which i writen in sql db.

select * from student_details where (child_name like @Student_ID or student_id like @Child_Name) and School_Name=@School_Name
Hi Try This

SQL
DECLARE @Input VARCHAR(100)='S'
SELECT tudent_id, Name, Class, Created_on FROM Student WHERE Name LIKE @Input+'%'


Check the following Links

SQL LIKE Operator[^]

SQL wildcards and like operator[^]

Regards
GVPrabu
 
Share this answer
 
Comments
ntitish 2-Mar-13 7:42am    
thanks sir.....
ntitish 2-Mar-13 7:42am    
thanks a lot sir...i solved my problem partially...
sir i am having one more problem. that was, when i am typing the name in the text-box like 's' i want to see the related records in grid-view.actually i am getting the result but when ever the cursor moving from the text_box it showing the grid-view with related records but what i want is when i am typing the name only i want to see the records is it possible sir....even i seen in so many shopping sites....
gvprabu 2-Mar-13 7:44am    
I am a Database Developer , I will give the example by Monday.... I will ask my friends.
gvprabu 2-Mar-13 7:47am    
check in Google, Auto Complete Text in Dot net or C#...
gvprabu 2-Mar-13 7:48am    
Check this

http://www.codeproject.com/Articles/8020/Auto-complete-Control

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