• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1263
  • Last Modified:

Getting SqlDataSource SelectParameters from a TextBox control

How do I pass the current value of a TextBox control into the SelectParameters list of a SqlDataSource?

Here is what I have:
<asp:TextBox ID="tbLimit" runat="server" Text="20"></asp:TextBox> most recent queries.
<asp:SqlDataSource ID="MySqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:CMAConnection %>" ProviderName="<%$ ConnectionStrings:CMAConnection.ProviderName %>" SelectCommand="CALL RecentQueries">
  <SelectParameters>
    <asp:ControlParameter Name="?_Limit" ControlID="tbLimit" DefaultValue="20" Type="Int32" />
  </SelectParameters>
</asp:SqlDataSource>

and I get the error:
Incorrect number of arguments for PROCEDURE cmainfo.RecentQueries; expected 1, got 0
0
DerekWatling
Asked:
DerekWatling
  • 5
  • 4
1 Solution
 
cmhuntyCommented:
Change
<asp:ControlParameter Name="?_Limit" ControlID="tbLimit" DefaultValue="20" Type="Int32" />
for
<asp:ControlParameter Name="?_Limit" ControlID="tbLimit" DefaultValue="20" Type="Int32" PropertyName="text" />

Means you're taking the text property of the control.

You'll need a vailidator to ensure it's int32 though.
0
 
DerekWatlingAuthor Commented:
Still giving the same error.
0
 
cmhuntyCommented:
I would suggest that it's something to do with the name of the parameter. Try removing the ? before the _Limit.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
DerekWatlingAuthor Commented:
Already tried that. Just keeps telling me it's not getting the parameter.
0
 
DerekWatlingAuthor Commented:
Even tried adding the parameter programmaticaly in the Page_Load (with and without the ?):
  MySqlDataSource.SelectParameters.Add("?_Limit", CType(tbLimit.Text, Integer)
and I get the same error!
0
 
cmhuntyCommented:
And that's definitely the right name of parameter in the procedure? Can you copy the top of the stored proc?
0
 
DerekWatlingAuthor Commented:
CREATE PROCEDURE `RecentQueries`(IN _Limit INTEGER(11))
0
 
cmhuntyCommented:
Are you using Visual Studio?

If so, can you create an Updating method on MySQLDatasource and put a breakpoint in From there, can you do a watch on MySQLDataSource and see if it suggests that any parameters are present?
0
 
DerekWatlingAuthor Commented:
Found the problem in the SelectCommand:
<asp:SqlDataSource ID="MySqlDataSource" runat="server" ... SelectCommand="CALL RecentQueries(?limit)">
  <SelectParameters>
    <asp:ControlParameter Name="limit" ControlID="tbLimit" PropertyName="text" Type="Int32" />
  </SelectParameters>
</asp:SqlDataSource>
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now