Results 1 to 6 of 6

Thread: [RESOLVED] [2005] Find within the string.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Resolved [RESOLVED] [2005] Find within the string.

    I am using the following code for finding the customer name as and when i type in the Combobox.
    Code:
    Private Sub combobox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.TextChanged
            If btnact = "S" Then
                CUSTOMERBindingSource.Filter = "name like '" & ComboBox2.Text & "%'"
            End If
        End Sub
    I want to look for the string anywhere within the name. For eg. i want to find 'Jack' from the names of the customers then it should give me the result matching 'Jack' in the 1st name or middle name or last name. However the names of the customer are stored as a single string only. Suppose i have three names in my database containing the word 'Jack' within the string then it should give me the following results
    1. Jack Brown
    2. Michael Jackson
    3. Phill Jack Robinson

    What changes do i have to make to my code ?

  2. #2
    Hyperactive Member koolprasad2003's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    443

    Arrow Re: [2005] Find within the string.

    Quote Originally Posted by LuxCoder
    I am using the following code for finding the customer name as and when i type in the Combobox.
    Code:
    Private Sub combobox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.TextChanged
            If btnact = "S" Then
                CUSTOMERBindingSource.Filter = "name like '" & ComboBox2.Text & "%'"
            End If
        End Sub
    I want to look for the string anywhere within the name. For eg. i want to find 'Jack' from the names of the customers then it should give me the result matching 'Jack' in the 1st name or middle name or last name. However the names of the customer are stored as a single string only. Suppose i have three names in my database containing the word 'Jack' within the string then it should give me the following results
    1. Jack Brown
    2. Michael Jackson
    3. Phill Jack Robinson

    What changes do i have to make to my code ?
    just use
    if string name.Contains("Jack/whatever") then
    //add this name in arraylist
    end if

    thankx
    Koolprasad2003
    MCP, MCTS, Microsoft MVP [Asp.Net/IIS]

    For more .NET development tips visit .NET Tips

    If the post is useful then please Rate it

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: [2005] Find within the string.

    i dint get u.... plz explain where should i use it ?

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

    Re: [2005] Find within the string.

    You've got a wildcard AFTER your string value, so that's only going to find matches that START with that value. If you want to find matches anywhere in the string then you need a wildcard BEFORE the string too.
    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

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: [2005] Find within the string.

    U mean like this:

    Code:
    CUSTOMERBindingSource.Filter = "name like '%" & ComboBox2.Text & "%'"

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: [2005] Find within the string.

    thanks that worked !

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