Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting 'too many parameters passed' to stored procedure on ASPX page
    primarykey
    data
    text
    <p>I'm having trouble figuring this error out. I have a grid on an ASPX page that displays data from a stored procedure in an SQL Server 2008 database. When the page loads, I get the following error:</p> <pre><code>"Procedure or function &lt;sp_name&gt; has too many arguments specified." </code></pre> <p>Here is the code for the grid and the datasource:</p> <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" ShowFooter="True" OnRowDataBound="GridView1_RowDataBound" AllowSorting="True"&gt; &lt;Columns&gt; &lt;asp:BoundField DataField="MerchantID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="MerchantID" /&gt; &lt;asp:BoundField DataField="MerchantName" HeaderText="Merchant" SortExpression="MerchantName" /&gt; &lt;asp:BoundField DataField="RapidTuitionID" HeaderText="RapidTuition ID" SortExpression="RapidTuitionID" /&gt; &lt;asp:BoundField DataField="DateCreated" HeaderText="Enrolled" SortExpression="DateCreated" /&gt; &lt;asp:TemplateField HeaderText="Commands"&gt; &lt;ItemTemplate&gt; &lt;asp:LinkButton ID="ImpersonateUserLinkButton" runat="server" OnClick="Command_Click" CommandName="impersonate" CommandArgument='&lt;%# Eval("MerchantID") %&gt;' CssClass="table_command"&gt;Impersonate&lt;/asp:LinkButton&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;EmptyDataTemplate&gt; No data to display. &lt;/EmptyDataTemplate&gt; &lt;PagerStyle CssClass="pager" /&gt; &lt;/asp:GridView&gt; &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:Development %&gt;" SelectCommand="sp_GatewayMerchants" SelectCommandType="StoredProcedure"&gt; &lt;SelectParameters&gt; &lt;asp:ControlParameter ControlID="PromotionPlaceHolderTop$StartDate" Name="StartDate" DefaultValue="1/1/2010" PropertyName="Text" Type="DateTime" /&gt; &lt;asp:ControlParameter ControlID="PromotionPlaceHolderTop$EndDate" Name="EndDate" DefaultValue="12/31/2010" PropertyName="Text" Type="DateTime" /&gt; &lt;asp:ControlParameter ControlID="PromotionPlaceHolderTop$StatusActive" DefaultValue="true" Name="StatusActive" PropertyName="Checked" Type="Boolean" /&gt; &lt;asp:ControlParameter ControlID="PromotionPlaceHolderTop$StatusDeactive" DefaultValue="true" Name="StatusDeactive" PropertyName="Checked" Type="Boolean" /&gt; &lt;/SelectParameters&gt; &lt;/asp:SqlDataSource&gt; </code></pre> <p>Here's the code from the stored procedure:</p> <pre><code>ALTER PROCEDURE [dbo].[sp_GatewayMerchants] -- Add the parameters for the stored procedure here @StartDate DateTime, @EndDate DateTime, @StatusActive bit, @StatusDeactive bit AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here SELECT m.MerchantID AS [ID], m.MerchantName, CASE m.StatusFlag WHEN 1 THEN 'Active' ELSE 'Deactive' END AS [Status], m.RapidTuitionID, m.DateCreated FROM Merchant m WHERE (CONVERT(varchar,m.DateCreated,112) BETWEEN CONVERT(varchar,CONVERT(DATETIME,@StartDate,101),112) AND CONVERT(varchar,CONVERT(DATETIME,@EndDate,101),112)) AND ( (@StatusActive = 1 AND m.StatusFlag = 1) OR (@StatusDeactive = 1 AND m.StatusFlag = 0) ) ORDER BY m.MerchantName END </code></pre> <p>The datasource is passing 4 parameters, and the stored procedure is accepting 4, but when the page displays I get the error mentioned above. Am I missing something here?</p> <p><strong>EDIT:</strong> Here's the code behind for the template column. But I'm not sure how this could be causing extra parameters to the SP.</p> <pre><code> protected void Command_Click(object sender, EventArgs e) { var merchantID = Convert.ToInt32(((LinkButton)sender).CommandArgument); switch (((LinkButton)sender).CommandName) { case "impersonate": var gs = GatewaySession.Parse(Page.User.Identity.Name); gs.Role = GatewaySession.RoleEnum.Merchant; gs.MerchantID = merchantID; gs.CustomerID = -1; FormsAuthentication.SetAuthCookie(gs.ToString(), false); Page.Session["MerchantID"] = gs.MerchantID; Response.Redirect("/Merchant/Default.aspx"); break; } } </code></pre> <p>If I remove the ASP:LINKBUTTON the code works. So why would a LINKBUTTON be causing this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload