|
-
Sep 12th, 2008, 09:00 AM
#1
Thread Starter
Addicted Member
Help creating A - Z search buttons
I have been asked to include a search page for my database that uses a simple A - Z button interface to select customer records by last name, and allow the end user to scroll through a datagridview to pick the user they want.
I can handle 95% of this additional form with any trouble (in fact, if I wanted to do it the hard way, I could get all of it!). However, I want to make these buttons as efficient as possible by using only one subroutine to handle all of them. Basically, how can I pass the Tag information from the button into the subroutine and use it for the query?
I'm thinking the sub declaration wil include a strTag as String in the () section, but I don't know how to send the Tag from the button to that declaration.
Any help?
-
Sep 12th, 2008, 09:55 AM
#2
Re: Help creating A - Z search buttons
E.g.
vb.net Code:
Private Sub Search(ByVal text As String) Using connection As New SqlConnection("connection string here") Using command As New SqlCommand("SELECT * FROM MyTable WHERE Name LIKE @Name", connection) command.Parameters.AddWithValue("@Name", text & "%") '... End Using End Using End Sub Private Sub Buttons_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonA.Click, ... , ButtonZ.Click Me.Search(CStr(DirectCast(sender, Button).Tag)) End Sub
-
Sep 12th, 2008, 11:05 AM
#3
Thread Starter
Addicted Member
Re: Help creating A - Z search buttons
Thanks, jcm, that's pretty straight-forward and I think it will work.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|