Parameter problem with Gridview updating using SQL Datasource & Stored Procedures

Posted on 2008-10-20
Last Modified: 2013-11-08

I am trying to use the gridview and datasource control to view and edit database information. However, I am having a problem when trying to update the information.   The datasource uses two different stored procedures, as you can see in the code.  

The problem that seems to be thrown is once I have clicked the update button, it shows the following error:
"Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Procedure or function spUpdateRecipients has too many arguments specified."

The update stored procedure has three parameters:
@active int
@configNum int
@user varchar(50)

The datasource was set up using the IDE not in code, but it only has two parameters put in for some reasons.  I thought this might have been the issue, but upon adding in the third it still gives the same error...

                            <asp:Parameter Name="active" Type="Int32" />
                            <asp:Parameter Name="configNum" Type="Int32" />
<asp:Parameter Name="user" Type="String" />

If anyone could give me some ideas of how to fix this it would be great.

<%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ModifyRecipients.aspx.cs" Inherits="ReportRecipients2008.ModifyRecipients" Title="Untitled Page" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<div style="width:100%">

            <asp:UpdatePanel ID="UpdatePanel1" runat="server">


                    <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged" RepeatDirection="Horizontal">

                        <asp:ListItem Value="0">Study Number</asp:ListItem>

                        <asp:ListItem Value="1">Protocol ID</asp:ListItem>


                    <asp:MultiView ID="MultiView1" runat="server">

                        <asp:View ID="vwStudyNum" runat="server">

                            <asp:SqlDataSource ID="dsCountries" runat="server" 

                                ConnectionString="<%$ ConnectionStrings:GPMConnectionString %>" 

                                SelectCommand="SELECT DISTINCT [CountryDescription] FROM [Countries]">


                            <cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender1" runat="server" 

                                TargetControlID="tbStudyNumber1" WatermarkText="Enter Study Number"></cc1:TextBoxWatermarkExtender>

                            <asp:DropDownList ID="ddlCountries" runat="server" AppendDataBoundItems="True" 

                                DataSourceID="dsCountries" DataTextField="CountryDescription" 


                                <asp:ListItem>All Countries / None</asp:ListItem>


                            <asp:TextBox ID="tbStudyNumber1" runat="server"></asp:TextBox>

                            <asp:Button ID="btnSearch" runat="server" OnClick="btnSearch_Click" 

                                Text="Search" />

                            <br /><br />




                        <asp:View ID="vwProtocolNum" runat="server">

                            <asp:TextBox ID="tbProtocolId2" runat="server" ReadOnly="True"></asp:TextBox>

                            <asp:Label ID="Label4" runat="server" Text="Enter protocol ID"></asp:Label>



                    <br />

                    <asp:GridView  BorderWidth="0px" ID="grdvUserInfo" runat="server" 

                        DataSourceID="dsRecips" BackColor="White" CellPadding="4" 

                        ForeColor="Black" GridLines="Vertical" Width="500px" 

                        AutoGenerateColumns="False" onrowdatabound="grdvUserInfo_RowDataBound" 

                        DataKeyNames="Recip,Config_Num" EmptyDataText="No data returned">

                        <FooterStyle BackColor="#CCCC99" />

                        <RowStyle BackColor="#CCCCCC" ForeColor="Black" BorderColor="Black" BorderStyle="Solid" />


                            <asp:CommandField ButtonType="Image" CancelImageUrl="~/Images/cancel.png" 

                                EditImageUrl="~/Images/edit.png" HeaderText="Modify" ShowCancelButton="False" 

                                ShowEditButton="True" UpdateImageUrl="~/Images/save.png">

                                <ControlStyle Height="16px" Width="16px" />


                            <asp:BoundField DataField="Recip" HeaderText="Recip" ReadOnly="True" 

                                SortExpression="Recip" />

                            <asp:TemplateField HeaderText="Active" SortExpression="Active">


                                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Active") %>'></asp:TextBox>



                                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("Active") %>'></asp:Label>



                            <asp:BoundField DataField="Config_Num" HeaderText="Config_Num" SortExpression="Config_Num" 

                                Visible="True" ReadOnly="True" />


                        <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />

                        <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />

                        <HeaderStyle BackColor="DimGray" Font-Bold="True" ForeColor="White" />

                        <AlternatingRowStyle BackColor="#E0E0E0" />


                    <asp:SqlDataSource ID="dsRecips" runat="server" 

                        ConnectionString="<%$ ConnectionStrings:ReportingConnectionString %>" 


                        SelectCommandType="StoredProcedure" UpdateCommand="spUpdateRecipients" 



                            <asp:Parameter Name="country" Type="String" />

                            <asp:Parameter Name="jobId" Type="Int32" />



                            <asp:Parameter Name="active" Type="Int32" />

                            <asp:Parameter Name="configNum" Type="Int32" />





            <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1"



                    <div id="loadScreen">

                        <div id="loadScreenDetail">

                            <div id="loadScreenDetailMessage">                    

	                            <img height="15" src="Images/ajax-loader.gif" alt="loading image"/>

                                Updating, please wait...








Open in new window

Question by:Artform04
  • 2
LVL 13

Expert Comment

ID: 22758268
a. can you post the header part of your sproc.

b.You say you added the third param yet i dont see it in the code you posted.

c.Can you post your code behind

I notice nothing is binding to your 'configNum'  and  'user' params....
only 'active'
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Active") %>'></asp:TextBox>
unless your doing this in the code behind..

Author Comment

ID: 22758519
Hey thanks for the reply.  In response to what you said...

a) here is the SPROC header:
USE [Reporting]
/****** Object:  StoredProcedure [dbo].[spUpdateRecipients]    Script Date: 10/20/2008 15:50:08 ******/

ALTER PROCEDURE [dbo].[spUpdateRecipients]
@active int,
@configNum int,
@user varchar(50)

b) In the original question, I showed you waht I put, however it didnt make any difference so I reverted it back to the IDE generated version (two params)
c) The code file is attached below.
d) As regards the binding, I converted the "Active" field to a template field as I jsut wanted to check it was using "bind" and not "eval".  The other items are boundfields which I believe are automatically bound with the datafield property e.g. DataField="Recip"

Thanks, hope the material provided can help you help me...
using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Xml.Linq;

namespace ReportRecipients2008


    public partial class ModifyRecipients : System.Web.UI.Page


        protected void Page_Load(object sender, EventArgs e)


            if (!Page.IsPostBack)


                RadioButtonList1.SelectedIndex = 0;

                MultiView1.ActiveViewIndex = RadioButtonList1.SelectedIndex;



        protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)


            MultiView1.ActiveViewIndex = RadioButtonList1.SelectedIndex;

            grdvUserInfo.Visible = false;



        protected void btnSearch_Click(object sender, EventArgs e)


            //set the parameter value for the select

            dsRecips.SelectParameters["jobId"].DefaultValue = tbStudyNumber1.Text;

            if (ddlCountries.SelectedIndex == 0)


                dsRecips.SelectParameters["country"].DefaultValue = "";




                dsRecips.SelectParameters["country"].DefaultValue = ddlCountries.SelectedValue;


            //get the new information


            grdvUserInfo.Visible = true;



        protected void grdvUserInfo_RowDataBound(object sender, GridViewRowEventArgs e)


            if (Page.IsPostBack) {



                    e.Row.BorderWidth = 0;

                    if (e.Row.Cells[1].Text == "1")


                        e.Row.BackColor = System.Drawing.Color.LightGreen;

                        e.Row.Cells[1].Text = "Y";


                    else if (e.Row.Cells[1].Text == "0")


                        e.Row.Cells[1].Text = "N";



                catch (Exception)


                 // no problem, just trying to look at cells when there is no data so ignore






Open in new window


Accepted Solution

Artform04 earned 0 total points
ID: 22765630
I have discovered the problem.  Visual Studio is automatically adding in Key's as parameters on top of the ones in the code, resulting in too many parameters.

To resolve this you need to either remove the doubled parameters in the ASPX codefile (the duplicate of the key)


In the datasource.updating event, delete the problem parameter.  The code i used for this is attached...

protected void dsRecips_Updating(object sender, SqlDataSourceCommandEventArgs e)


            int indexParam = 0;

            bool isFound = false;

            //search for the problem additional parameter which is added automatically by VS

            foreach (System.Data.SqlClient.SqlParameter xP in e.Command.Parameters)


                //check if this is the trouble extra parameter

                if (xP.ParameterName == "@ConfigNum" && xP.SqlValue == null)


                    //this is the problem parameter, set to found and exit the loop

                   isFound = true;



                //the param wasnt found so increment the index counter



            //if the parameter was found, remove it from the parameters collection

            if (isFound == true)





Open in new window


Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now