Results 1 to 5 of 5

Thread: bindingsource filter 2 columns

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2014
    Posts
    184

    bindingsource filter 2 columns

    Hello dear vb friends,

    as the title says, i want to search in 2 columns not only in one. i didnt figure out what i have to do. this is my code what works fine but it only searcheds in "Name" Column.

    DtKundenBindingSource.Filter = "Name like '" & tb_suchen.Text & "%'"

    .

    I tried this but error appears.
    DtKundenBindingSource.Filter = "Name like '" & tb_suchen.Text & "%'" And "Street like '" & tb_suchen.Text & "%'"

  2. #2
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: bindingsource filter 2 columns

    Code:
    DtKundenBindingSource.Filter = String.Format("Name Like = '{0}' AND Street Like = '{1}'", tb_suchen.Text & "%" , tb_suchen.Text & "%")
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2014
    Posts
    184

    Re: bindingsource filter 2 columns

    I had to remove the = in your code now it works. also i changed AND to Or because i want to search in column NAme OR Strasse.This is my code now. Thanks.
    Code:
    DtKundenBindingSource.Filter = String.Format("Name Like  '{0}' or Strasse Like '{1}'", tb_suchen.Text & "%", tb_suchen.Text & "%")

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

    Re: bindingsource filter 2 columns

    It's a small thing but why concatenate Strings when you're already using String.Join?
    Code:
    DtKundenBindingSource.Filter = String.Format("Name Like  '{0}%' or Strasse Like '{1}%'", tb_suchen.Text, tb_suchen.Text)

  5. #5
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: bindingsource filter 2 columns

    I had to remove the = in your code now it works.
    Doh of course the equals shouldn't be there i did that in a bit of a rush.

    It's a small thing but why concatenate Strings when you're already using String.Join?
    I didn't even think about doing that JMC but your right its nicer and neater
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



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