如何为我的查询将所选RadioButtonList项绑定到controlParameter?
我有以下内容,但得到了[OleDbException (0x80040e14): Missing operand.] System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +1216113 ...错误。
<asp:TextBox runat="server" id="first" ></asp:TextBox> Enter Account (Owner ID) Number with dashes if applicable. <br />
<asp:TextBox runat="server" id="second" ></asp:TextBox><br />
<asp:TextBox runat="server" id="third" ></asp:TextBox><br />
...
...
<asp:RadioButtonList id="accountType" runat="server">
<asp:ListItem text="foo" value="foo" selected="true"/>
<asp:ListItem text="bar" value="bar" />
</asp:RadioButtonList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:db %>" ProviderName="<%$ ConnectionStrings:db.ProviderName %>"
SelectCommand="SELECT * FROM dbtable WHERE (ACCT = @first OR ACCT = @second OR ACCT = @third) AND unpaid > 0 AND type = @accountTypeSelect ORDER BY acct ASC" >
<SelectParameters>
<asp:ControlParameter ControlID="first" Name="first" PropertyName="Text" Type="String" DefaultValue ="-1" />
<asp:ControlParameter ControlID="second" Name="second" PropertyName="Text" Type="String" DefaultValue ="-1"/>
<asp:ControlParameter ControlID="third" Name="third" PropertyName="Text" Type="String" DefaultValue ="-1" />
<asp:ControlParameter ControlID="accountType" Name="accountTypeSelect" PropertyName="SelectedValue" type="String"/>
</SelectParameters>
</asp:SqlDataSource>发布于 2020-12-09 06:27:16
您可以使用@controlname命名控件属性并将其添加到sql中,请查看此链接中的示例SqlDataSource.SelectParameters Property。
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:db %>" ProviderName="<%$ ConnectionStrings:db.ProviderName %>"
SelectCommand="SELECT * FROM dbtable WHERE (ACCT = @first OR ACCT = @second OR ACCT = @thrid) AND unpaid > 0 AND type = @accountTypeSelect ORDER BY acct ASC" >
<SelectParameters>
<asp:ControlParameter ControlID="first" Name="first" PropertyName="Text" Type="String" DefaultValue ="-1" />
<asp:ControlParameter ControlID="second" Name="second" PropertyName="Text" Type="String" DefaultValue ="-1"/>
<asp:ControlParameter ControlID="third" Name="third" PropertyName="Text" Type="String" DefaultValue ="-1" />
<asp:ControlParameter ControlID="accountType" Name="accountTypeSelect" PropertyName="SelectedValue" type="String"/>
</SelectParameters>
</asp:SqlDataSource>https://stackoverflow.com/questions/65206950
复制相似问题