We help IT Professionals succeed at work.
Get Started

Parameter problem with Gridview updating using SQL Datasource & Stored Procedures

Artform04
Artform04 asked
on
4,426 Views
Last Modified: 2013-11-08
Hi,

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...

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


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

Thanks!
<%@ 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">
                <ContentTemplate>
                    <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:RadioButtonList>
                    <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]">
                            </asp:SqlDataSource>
                            <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" 
                                DataValueField="CountryDescription">
                                <asp:ListItem>All Countries / None</asp:ListItem>
                            </asp:DropDownList>                            
                            <asp:TextBox ID="tbStudyNumber1" runat="server"></asp:TextBox>
                            <asp:Button ID="btnSearch" runat="server" OnClick="btnSearch_Click" 
                                Text="Search" />
                            <br /><br />
                            <div>
                            </div>
                        </asp:View>
                        <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>
                        </asp:View>
                    </asp:MultiView>
                    <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" />
                        <Columns>
                            <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:CommandField>
                            <asp:BoundField DataField="Recip" HeaderText="Recip" ReadOnly="True" 
                                SortExpression="Recip" />
                            <asp:TemplateField HeaderText="Active" SortExpression="Active">
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Active") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("Active") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField DataField="Config_Num" HeaderText="Config_Num" SortExpression="Config_Num" 
                                Visible="True" ReadOnly="True" />
                        </Columns>
                        <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:GridView>
                    <asp:SqlDataSource ID="dsRecips" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:ReportingConnectionString %>" 
                        SelectCommand="spGetRecipientsByJobIDCountry" 
                        SelectCommandType="StoredProcedure" UpdateCommand="spUpdateRecipients" 
                        UpdateCommandType="StoredProcedure">
                        <SelectParameters>
                            <asp:Parameter Name="country" Type="String" />
                            <asp:Parameter Name="jobId" Type="Int32" />
                        </SelectParameters>
                        <UpdateParameters>
                            <asp:Parameter Name="active" Type="Int32" />
                            <asp:Parameter Name="configNum" Type="Int32" />
                        </UpdateParameters>
                    </asp:SqlDataSource>
                </ContentTemplate>
            </asp:UpdatePanel>
            <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1"
                DisplayAfter="300">
                <ProgressTemplate>                    
                    <div id="loadScreen">
                        <div id="loadScreenDetail">
                            <div id="loadScreenDetailMessage">                    
	                            <img height="15" src="Images/ajax-loader.gif" alt="loading image"/>
                                Updating, please wait...
                            </div>   
                         </div>
                    </div>
                </ProgressTemplate>
            </asp:UpdateProgress>
        </div>
 
</asp:Content>

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE