1

私はこれを持っていますSqlDataSource

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConflictDetection="CompareAllValues"
    ConnectionString="<%$ ConnectionStrings:OracleXexdb %>" 
    ProviderName="<%$ ConnectionStrings:OracleXexdb.ProviderName %>"
    SelectCommand="select col1, col2, col3 from table where col1 < 2000 and (col2 = :col2 OR :col2 is null)"
     OnSelecting="SqlDataSource1_Selecting"
    >
    <SelectParameters>
        <asp:ControlParameter ControlID="codagent" Name="col2" PropertyName="Text" Type="String" ConvertEmptyStringToNull="true" DefaultValue=""/>
    </SelectParameters>
</asp:SqlDataSource>

codagentは で<asp:TextBox>あり、ユーザーは値を入力することも何も入力しない ("") こともできます。ユーザーが何も入力せずに TextBox を離れると、 はSqlDataSource値を取得しません。私の目標は、ユーザーがフィルターなしですべての col2 値を取得できるようにすることです

何か不足していますか?

4

4 に答える 4

1

SQLを次のように変更してみてください

SelectCommand="select col1, col2, col3 from table where col1 < 2000 and (col2 = :col2 OR  (:col2 is null AND 1=1)"

私は経験がないので、そのような式が Oracle で可能かどうかはよくわかりませんが、これは SQL Server で同じことを達成するために使用されるロジックです。

于 2013-09-23T18:45:43.233 に答える
1

私はこれを行う方法を見つけました:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConflictDetection="CompareAllValues"
    ConnectionString="<%$ ConnectionStrings:OracleXexdb %>" 
    ProviderName="<%$ ConnectionStrings:OracleXexdb.ProviderName %>"
    SelectCommand="select col1, col2, col3 from table where col1 < 2000 and (col2 = :col2 OR (:col2 is null))"
    >

    <SelectParameters>
        <asp:ControlParameter ControlID="codagent" Name="col2" PropertyName="Text" Type="String" ConvertEmptyStringToNull="false" DefaultValue=""/>
    </SelectParameters>

</asp:SqlDataSource>

これはうまくいきました

于 2013-10-01T21:48:33.707 に答える
0

サブクエリを使用しないのはなぜですか。次のコードは、col1 が空かどうかにかかわらず、col2、col3 を指定しています。

select (select col1 from table1 where col1 ='') as col1, col2, col3 from table1
于 2013-09-24T05:31:36.733 に答える