Results 1 to 3 of 3

Thread: fill table from combobox parameter

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Posts
    20

    fill table from combobox parameter

    I have a form that I can fill, navigate update, and edit etc with no problem.

    One of the columns in the dbtablethe form picks up from is "department" and I would like to be able to limit the data that gets returned into the datatable to the department chosen in the combobox. I can do this by adding the WHERE "department" =? and then setting the parameter to ? from the combobox.

    My problem is if i want to fill the dataset with all data regardless of department how do i do that? I was hoping I could set the ? as % and that would select everything but of course it didn't.

    Is there an easy answer or a better approach i should consider?

    Many Thanks

    Scott

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

    Re: fill table from combobox parameter

    Use LIKE instead of = in your SQL statement. LIKE behaves the same as = if the value has no wildcards. So your SQL should be "WHERE department LIKE ?" and then you would set the parameter value to "%" to retrieve everything. An alternative may be to just retrieve everything in the first place and then just set the DefaultView.RowFilter property of your DataTable to filter the data displayed based on the selection in your ComboBox.
    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
    Junior Member
    Join Date
    Sep 2005
    Posts
    20

    Re: fill table from combobox parameter

    wow you get about! every .net forum ive been on I see your name helping everyone. respect to you!

    I knew of LIKE but didn't know the wild card worked with it. I will try it out! if not i will try your other sugestion.

    Thanks for your help
    Scott

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