如何将null传递给asp:参数

时间:2012-08-27 02:56:47

标签: c# .net

我有以下代码:

<asp:SqlDataSource ID="dsLeave" 
                   runat="server" 
                   ConnectionString="<%$ ConnectionStrings:test %>"
                   SelectCommand="app_leave_notification_select"
                   SelectCommandType="StoredProcedure">
    <SelectParameters>
        <asp:Parameter Name="employee_id" Type="int32" />
    </SelectParameters>                
</asp:SqlDataSource>

有谁知道如何将null传递给asp:参数employee_id?

2 个答案:

答案 0 :(得分:3)

在参数中添加ConvertEmptyStringToNull="true",以便它像:

<asp:Parameter Name="employee_id" 
               Type="int32" 
               ConvertEmptyStringToNull="true" /> 

在空字符串中添加pass。

我从这篇博文中得到了这个:http://www.blog.sumantdubey.com/post/SQLDataSource-Passing-Null-Parameters.aspx

答案 1 :(得分:1)

<asp:Parameter Name="employee_id" 
               Type="Int32?" 
               ConvertEmptyStringToNull="true" />