Results 1 to 3 of 3

Thread: Help creating A - Z search buttons

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Location
    Bunker Hill, WV
    Posts
    154

    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?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Help creating A - Z search buttons

    E.g.
    vb.net Code:
    1. Private Sub Search(ByVal text As String)
    2.     Using connection As New SqlConnection("connection string here")
    3.         Using command As New SqlCommand("SELECT * FROM MyTable WHERE Name LIKE @Name", connection)
    4.             command.Parameters.AddWithValue("@Name", text & "%")
    5.  
    6.             '...
    7.         End Using
    8.     End Using
    9. End Sub
    10.  
    11. Private Sub Buttons_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonA.Click, ... , ButtonZ.Click
    12.     Me.Search(CStr(DirectCast(sender, Button).Tag))
    13. End Sub
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Location
    Bunker Hill, WV
    Posts
    154

    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
  •  



Click Here to Expand Forum to Full Width