本文介绍了添加ControlParameter到SqlDataSource的prevents查询和数据绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个调用存储过程的SqlDataSource和它工作正常。如果我添加一个< ControlParameter> 标签添加一个额外的参数,那么查询从未火灾和永远不会发生的数据绑定。建议?

I have a SqlDataSource that calls a stored procedure and it works fine. If I add a <ControlParameter> tag to add an additional argument, then the query never fires and the databinding never occurs. Suggestions?

这工作

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultDB %>"
    SelectCommand="SP_WHATEVER" SelectCommandType="StoredProcedure" 
    UpdateCommand="SP_WHATEVER2" UpdateCommandType="StoredProcedure">
    <SelectParameters>
        <asp:SessionParameter DefaultValue="" Name="UserName" SessionField="RP_Program" Type="String" />
    </SelectParameters>
    <UpdateParameters>
        <snip...>
    </UpdateParameters>
</asp:SqlDataSource>

当我添加ControlParameter,数据绑定不再出现

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultDB %>"
    SelectCommand="SP_WHATEVER" SelectCommandType="StoredProcedure" 
    UpdateCommand="SP_WHATEVER2" UpdateCommandType="StoredProcedure">
    <SelectParameters>
        <asp:SessionParameter DefaultValue="" Name="UserName" SessionField="RP_Program" Type="String" />
        <asp:ControlParameter Name="SprocArgName" ControlID="ddlFilter" PropertyName="SelectedValue" Type="String" />
    </SelectParameters>
    <UpdateParameters>
        <snip...>
    </UpdateParameters>
</asp:SqlDataSource>

在ControlParameter指的是页面上的有效对象。任何其他建议?

The ControlParameter refers to a valid object on the page. Any other suggestions?

推荐答案

最有可能的参​​数之​​一为空或空。添加CancelSelectOnNullParameter =假到ASP:SqlDataSource和ConvertEmptyStringToNull =true以这两个参数。一旦它的工作原理,调整参数,使SP获得什么,预计。

Most likely one of the parameter is empty or null. Add CancelSelectOnNullParameter="false" to the asp:SqlDataSource and ConvertEmptyStringToNull="true" to both parameters. Once it works, tweak the parameters so that SP gets what it expects.

这篇关于添加ControlParameter到SqlDataSource的prevents查询和数据绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 22:07