• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1298
  • 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

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