Michael Corban Michael Corban - 1 year ago 58
SQL Question

How can I use a case statement with a Drop Box? Access Database

I have a drop box with various items when the value is set to null I want to select multiple items using the control parameter to fill the data source like below.
This Select Command will not work can anyone help me to see what I'm doing in error? EDIT THE CODE BELOW IS NOW CORRECT AND FUNCTIONS.....

<asp:DropDownList ID="FilterList1" runat="server">

<asp:ListItem Selected="True" Value=" ">Produce</asp:ListItem>

<asp:AccessDataSource ID="AccessDataSource1" runat="server"
SelectCommand="SELECT * FROM [Table1] WHERE IIF( (@Food1 =' '), [Food] In ('Fruit','Vegetable'), (Food =@Food1) )">
<asp:ControlParameter ControlID="FilterList1" Name="Food1"
PropertyName="SelectedValue" Type="String" />


As you are using AccessDataSource1, then try Access SQL IIF() Statement, something like:

SelectCommand="SELECT * FROM [Table1] WHERE (Service =@Service1) OR IIF((@Service1 ='  '), IIF( [Service] In ('In Service','Out of Service'), True, False), False)

Also, make sure you are using correct syntax @Service1 =' ' (may be @Service1 ='' ?)

Hope this will help.