Search database with dropdownlist

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • OuTCasT
    Contributor
    • Jan 2008
    • 374

    Search database with dropdownlist

    i have 4 dropdownlist boxes on my form.
    it controls a datagridview on the page.
    The datagridview is populated with certain values from the selections of the dropdownlist boxes.
    i got the select statement to retrieve the information that i require from the different selections.
    Problem is that if i leave 1 dropdownlist box with no selection no information is returned into the datagridview..

    here is the select statement that ive used it works in query analyser so i figured that there might be something that has to be done on the page itself or dropdownlist boxes.

    [CODE=sql]SELECT * FROM [cvinformation] WHERE (([race] = CASE WHEN @race IS NOT NULL THEN @race ELSE [race] END) AND ([province] = CASE WHEN @province IS NOT NULL THEN @province ELSE [province] END) AND ([field] = CASE WHEN @field IS NOT NULL THEN @field ELSE [field] END) AND ([gender] = CASE WHEN @gender IS NOT NULL THEN @gender ELSE [gender] END))[/CODE]

    is there something that im doing wrong
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    You need to frame the SQL statement dynamically. If one drop down is not selected then that that column should not the included in the SQL statement to query the database table.

    Comment

    Working...