Results 1 to 3 of 3

Thread: Universal search to data view/table/grid

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Posts
    6

    Universal search to data view/table/grid

    Dear all,

    I created a winform that display an item master in a DataGridView, bound with a DataView. Let's just say it has columns/fields
    • item_id
    • item_name
    • item_description

    I wanted to make a single text box that will be searched in all fields. So if any field in a row contains searched item, it will be displayed.
    My current idea is to create a DataView with RowFilter contains all rows such

    Code:
    myDataView.RowFilter = "item_id LIKE '%" & Me.txtSearch.Text & "%' OR " & _
                           "item_name LIKE '%" & Me.txtSearch.Text & "%' OR " & _
                           "item_desc LIKE '%" & Me.txtSearch.Text & "%'"
    Is there any smarter way to do this?
    I'm afraid this code will cause a big slowdown for a larger dataset.....

    Thanks in advanced.

    Yoachan

  2. #2
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    351

    Re: Universal search to data view/table/grid

    From my personal experience I would say this is pretty good way of doing it. I use the same method to filter datasets of 10,000+

    You may want to consider your actual search string though. Firstly can item_id contain text characters? Then you shouldn't use the single quotes around them. When searching an Id field (usually a unique ID), it is rather odd to use a LIKE. If you put 1 in the text box, do you really want all records with 1 in the id number? Is that useful?

    In my experience, its better to provide a entry field for the user to enter the id number (if they know it), or if not, a single field to search name and description.
    Rico

    Using: VB.net & MS SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Posts
    6

    Re: Universal search to data view/table/grid

    @Enrico: Thanks for your reply.

    Quote Originally Posted by enrico1982 View Post
    From my personal experience I would say this is pretty good way of doing it. I use the same method to filter datasets of 10,000+
    It's a relief then

    Quote Originally Posted by enrico1982 View Post
    You may want to consider your actual search string though. Firstly can item_id contain text characters? Then you shouldn't use the single quotes around them.
    Yes, the item_id is a string and contain text characters

    Quote Originally Posted by enrico1982 View Post
    When searching an Id field (usually a unique ID), it is rather odd to use a LIKE. If you put 1 in the text box, do you really want all records with 1 in the id number? Is that useful?
    Thank you for your suggestions, putting more limit in the search will be much better approach

    Quote Originally Posted by enrico1982 View Post
    In my experience, its better to provide a entry field for the user to enter the id number (if they know it), or if not, a single field to search name and description.
    Separate text fields was my first approach.
    But in several forms (such item master lookup), I want to make as simple lookup form as possible, with as few navigation as needed.
    But for more complex report, your approach will be much better.

    Again, thanks

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