How to bind selected RadioButtonList item to controlParameter for my query?
I have following, but getting [OleDbException (0x80040e14): Missing operand.] System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +1216113 ...
error.
<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>
you can name control properties and added into your sql with @controlname, have a look at this link for examples 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>
User contributions licensed under CC BY-SA 3.0