[英]pass null value to stored procedure in sqldatasource when page is loading
I have some textboxes which are used to enter search values. 我有一些用于输入搜索值的文本框。 I have a stored procedure that has 2 datetimes, 1 int and 1 char parameter.
我有一个具有2个日期时间,1个int和1个char参数的存储过程。 I attach my
SqlDataSource
to a TextBox
and set the default value to null but when I run my project empty is passed to the stored procedure but my stored procedure expects a null value. 我将
SqlDataSource
附加到TextBox
并将默认值设置为null,但是当我运行我的项目时,会将空值传递给存储过程,但是我的存储过程期望使用null值。 How can I pass null with SqlDataSource
bound to textboxes? 如何将
SqlDataSource
绑定到文本框以传递null?
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DB_MosquesAffairsConnectionString3 %>"
SelectCommand="mqa.S_Conference_Select_Date"
SelectCommandType="StoredProcedure" onload="SqlDataSource1_Load"
onselecting="SqlDataSource1_Selecting">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" DbType="Date" DefaultValue="null"
Name="StartDate" PropertyName="Text" />
<asp:ControlParameter ControlID="TextBox2" DbType="Date" DefaultValue="null"
Name="EndDate" PropertyName="Text" />
<asp:ControlParameter ControlID="TextBox3" DefaultValue="null"
Name="ConferenceName" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="TextBox4" DefaultValue="null"
Name="ConferenceID" PropertyName="Text" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
You can use the following properties/attributes in ControlParameter
您可以在
ControlParameter
使用以下属性/属性
ConvertEmptyStringToNull="true" DefaultValue=""
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" DbType="Date" ConvertEmptyStringToNull="true" DefaultValue=""
Name="StartDate" PropertyName="Text" />
<asp:ControlParameter ControlID="TextBox2" DbType="Date" ConvertEmptyStringToNull="true" DefaultValue=""
Name="EndDate" PropertyName="Text" />
<asp:ControlParameter ControlID="TextBox3" ConvertEmptyStringToNull="true" DefaultValue=""
Name="ConferenceName" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="TextBox4" ConvertEmptyStringToNull="true" DefaultValue=""
Name="ConferenceID" PropertyName="Text" Type="Int32" />
</SelectParameters>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.