我有一些用于输入搜索值的文本框。我有一个存储过程有2个日期时间,1个int和1个char参数。我将SqlDataSource
附加到TextBox
并将默认值设置为null但是当我运行我的项目时,将空传递给存储过程,但我的存储过程需要空值。如何通过绑定到文本框的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>
答案 0 :(得分:1)
您可以在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>