在ASP.NET中使用更多WHERE参数的SQL查询,是否可能?

时间:2015-03-30 19:41:19

标签: c# asp.net database sqldatasource

所以这是我的代码:

<asp:SqlDataSource ID="UsersSearchResult" runat="server" ConnectionString="<%$ ConnectionStrings:UserQueries %>" ProviderName="<%$ ConnectionStrings:UserQueries.ProviderName %>" 
        SelectCommand="SELECT * FROM USERS WHERE ID = :userparameter1 OR FIRSTNAME = :userparameter2 OR LASTNAME = :userparameter3 OR
        USERNAME = :userparameter4 OR PASSWORD = :userparameter5 OR EMAIL = :userparameter6 OR GENDER = :userparameter7 OR
        BIRTHDATE = :userparameter8 OR NATIONALITY = :userparameter9 OR CURRENTCITY = :userparameter10">
        <SelectParameters>
            <asp:ControlParameter ControlID="SearchUsersBox" Name="userparameter1" PropertyName="Text" Type="Empty" />
            <asp:ControlParameter ControlID="SearchUsersBox" Name="userparameter2" PropertyName="Text" Type="Empty" />
            <asp:ControlParameter ControlID="SearchUsersBox" Name="userparameter3" PropertyName="Text" Type="Empty" />
            <asp:ControlParameter ControlID="SearchUsersBox" Name="userparameter4" PropertyName="Text" Type="Empty" />
            <asp:ControlParameter ControlID="SearchUsersBox" Name="userparameter5" PropertyName="Text" Type="Empty" />
            <asp:ControlParameter ControlID="SearchUsersBox" Name="userparameter6" PropertyName="Text" Type="Empty" />
            <asp:ControlParameter ControlID="SearchUsersBox" Name="userparameter7" PropertyName="Text" Type="Empty" />
            <asp:ControlParameter ControlID="SearchUsersBox" Name="userparameter8" PropertyName="Text" Type="Empty" />
            <asp:ControlParameter ControlID="SearchUsersBox" Name="userparameter9" PropertyName="Text" Type="Empty" />
            <asp:ControlParameter ControlID="SearchUsersBox" Name="userparameter10" PropertyName="Text" Type="Empty" />
        </SelectParameters>
    </asp:SqlDataSource>

我在这里要做的是当一个搜索参数使用OR语句查看数据库中的每一列时。我能这样做吗?如果是,怎么样?

1 个答案:

答案 0 :(得分:-1)

你必须使用where name1,name2,name3 OR name1,name2,name3