i have a search box , whose value txtbox1.Text is used as a filter in where clause, so gridview returns results on the basis of name entered in textbox but user would have to enter exact and full name in text box otherwise no record displays but i want that
even if user enters few sequential letters then it should display all matching records in gridview,
e.g if user enters Joh instead of Johnny , then on entering Joh , it should display Johnny and other similar names
SelectCommand="SELECT [userid], [fullname], [email], [question], [answers], [doc], [roleid],[active] FROM [tblUser] where fullname=@emplyrName AND roleid=2"
use the sql keyword "like" in conjunction with a wildcard. If you don't know what those are, I've heard good things about the book, Teach Yourself SQL in 10 Minutes.
Once you've got that part figured out your next task will be to make the search case insensitive.
Marked as answer by Hunain Hafeez on Nov 18, 2012 11:22 AM
use % and LIKE : SelectCommand="SELECT [userid], [fullname], [email], [question], [answers], [doc], [roleid],[active] FROM [tblUser] where fullname LIKE @emplyrName + '%' AND roleid=2"
SelectCommand="SELECT [userid], [fullname], [email], [question], [answers], [doc], [roleid],[active] FROM [tblUser] where (fullname Like @emplyrName+'%') AND roleid=2"
Hunain Hafee...
Member
238 Points
639 Posts
select query issue
Nov 17, 2012 08:37 PM|LINK
i have a search box , whose value txtbox1.Text is used as a filter in where clause, so gridview returns results on the basis of name entered in textbox but user would have to enter exact and full name in text box otherwise no record displays but i want that even if user enters few sequential letters then it should display all matching records in gridview,
e.g if user enters Joh instead of Johnny , then on entering Joh , it should display Johnny and other similar names
Dan Bracuk
Contributor
3970 Points
1096 Posts
Re: select query issue
Nov 17, 2012 10:57 PM|LINK
use the sql keyword "like" in conjunction with a wildcard. If you don't know what those are, I've heard good things about the book, Teach Yourself SQL in 10 Minutes.
Once you've got that part figured out your next task will be to make the search case insensitive.
oned_gk
All-Star
31806 Points
6503 Posts
Re: select query issue
Nov 18, 2012 12:55 AM|LINK
tarunSaini
Contributor
2948 Points
985 Posts
Re: select query issue
Nov 18, 2012 02:06 AM|LINK
use '%'
Hunain Hafee...
Member
238 Points
639 Posts
Re: select query issue
Nov 18, 2012 11:22 AM|LINK
thanks man and it is working case insensitively even i didn't thought about it but is doing dearch insensitively !