Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have working on my project and shows user data on grid view with update/delte option. the delete operation work fine, but when i apply update operation it gives error. that store procedure Procedure or function uspUpdateArticle has too many arguments specified.

Here is my Code:
SQL
Create Proc uspUpdateArticle
@ArticleID int, @Title varchar(50), @Body varchar(1000),
@Author varchar(50), @Categories varchar(30), @Updatedby int
As
BEGIN
SET NOCOUNT ON;
UPDATE TblArticles SET Title = @Title, Body = @Body, Author = @Author, Categories = @Categories, Updatedby = @Updatedby WHERE ArticleID = @ArticleID
END


C#
  <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ECII(Old)ConnectionString %>" SelectCommand="uspGetArticles" DeleteCommand="uspDeleteArticle"  UpdateCommandType="StoredProcedure" UpdateCommand="uspUpdateArticle" SelectCommandType="StoredProcedure" DeleteCommandType="StoredProcedure">
            <DeleteParameters>
                <asp:Parameter Name="ArticleID" Type="Int32" />
            </DeleteParameters>
            <SelectParameters>
                <asp:SessionParameter Name="PublishedBy" SessionField="UserID" Type="Int32" />
                <asp:SessionParameter Name="SubcriptionId" SessionField="SubscripID" Type="Int32" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="Title" Type="String" />
                <asp:Parameter Name="Body" Type="String" />
                <asp:Parameter Name="Author" Type="String" />
                <asp:Parameter Name="Categories" Type="String" />
                <asp:SessionParameter Name="Updatedby" SessionField="UserID" Type="Int32" />
                <asp:Parameter Name="ArticleID" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
        <div style="width: 98%; height: 500px; margin: 0 auto; margin-removed 10px; overflow: scroll;">

<asp:GridView ID="GridViewListallarticles" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" DataKeyNames="ArticleID" DataSourceID="SqlDataSource1" ForeColor="Black" GridLines="Vertical" Width="200%" OnSelectedIndexChanged="GridViewListallarticles_SelectedIndexChanged">
                <AlternatingRowStyle BackColor="White" />
                <Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ButtonType="Button" />
<asp:BoundField DataField="ArticleID" HeaderText="ArticleID" InsertVisible="False" ReadOnly="True" SortExpression="ArticleID" />

<asp:TemplateField HeaderText="Title" SortExpression="Title">
<EditItemTemplate><asp:TextBox ID="tbtitle" runat="server" Text='<%# Bind("Title") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidatortitle" Display="None" runat="server" ControlToValidate="tbtitle" Text="*" ErrorMessage="Please Input Article Title" ForeColor="Red" Font-Names="Calibri"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidatortitle" Display="None" runat="server" ControlToValidate="tbtitle" ValidationExpression="^[a-zA-Z''-'\s]{20,50}$" ErrorMessage="Article Title Name Must Contain Only 20-50 Characters" Text="*" Font-Names="Calibri" Font-Size="Small" ForeColor="Red"></asp:RegularExpressionValidator</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Title") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>


<asp:TemplateField HeaderText="Body" SortExpression="Body"><EditItemTemplate>
<asp:TextBox ID="tbbody" runat="server" Text='<%# Bind("Body") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorbody" Display="None" runat="server" ControlToValidate="tbbody" Text="*" ErrorMessage="Please Input Article Title" ForeColor="Red" Font-Names="Calibri"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidatorbody" Display="None" runat="server" ControlToValidate="tbbody" ValidationExpression="^.{50,500}$" ErrorMessage="Article Body Name Must Contain Only 50-500 Characters" Text="*" Font-Names="Calibri" Font-Size="Small" ForeColor="Red"></asp:RegularExpressionValidator></EditItemTemplate>
<ItemTemplate><asp:Label ID="Label2" runat="server" Text='<%# Bind("Body") %>'></asp:Label>
</ItemTemplate></asp:TemplateField>

<asp:TemplateField HeaderText="Author" SortExpression="Author">
<EditItemTemplate>
<asp:TextBox ID="tbauthor" runat="server" Text='<%# Bind("Author") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorauthor" Display="None" runat="server" ControlToValidate="tbauthor" Text="*" ErrorMessage="Please Input Author Name" ForeColor="Red" Font-Names="Calibri"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidatorauthor" Display="None" runat="server" ControlToValidate="tbauthor" ValidationExpression="^[a-zA-Z''-'\s]{10,50}$" ErrorMessage="Author Name Must Contain Only 1-50 Characters" Text="*" Font-Names="Calibri" Font-Size="Small" ForeColor="Red"></asp:RegularExpressionValidator></EditItemTemplate>
<ItemTemplate> <asp:Label ID="Label3" runat="server" Text='<%# Bind("Author") %>'></asp:Label></ItemTemplate></asp:TemplateField>

<asp:TemplateField HeaderText="Categories" SortExpression="Categories">
<EditItemTemplate>
<asp:TextBox ID="tbcategory" runat="server" Text='<%# Bind("Categories") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorcategory" Display="None" runat="server" ControlToValidate="tbcategory" Text="*" ErrorMessage="Please Input Article Category" ForeColor="Red" Font-Names="Calibri"></asp:RequiredFieldValidator></EditItemTemplate>
<ItemTemplate><asp:Label ID="Label4" runat="server" Text='<%# Bind("Categories") %>'></asp:Label</ItemTemplate></asp:TemplateField>

<asp:BoundField DataField="PublishedOn" HeaderText="PublishedOn" SortExpression="PublishedOn" />
<asp:BoundField DataField="PublishedBy" HeaderText="PublishedBy" SortExpression="PublishedBy" />
<asp:BoundField DataField="UpdatedOn" HeaderText="UpdatedOn" SortExpression="UpdatedOn" />
<asp:BoundField DataField="Updatedby" HeaderText="Updatedby" SortExpression="Updatedby" />
<asp:BoundField DataField="countlikes" HeaderText="countlikes" SortExpression="countlikes" />
<asp:BoundField DataField="SubcriptionId" HeaderText="SubcriptionId" SortExpression="SubcriptionId" />
</Columns>
<FooterStyle BackColor="#CCCC99" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FBFBF2" />
<SortedAscendingHeaderStyle BackColor="#848384" />
<SortedDescendingCellStyle BackColor="#EAEAD3" />
<SortedDescendingHeaderStyle BackColor="#575357" />
</asp:GridView></div>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" Font-Names="Calibri" Font-Size="Small" HeaderText="Invalid Input" ShowMessageBox="True" ShowSummary="False" />
Posted

Not sure, but found one solution.

Read - Updating gridview with SqlDataSource in asp.net[^].

Let me know if it helps or not.
 
Share this answer
 
Comments
Muhammad Taqi Hassan Bukhari 31-May-14 5:45am    
The Select Columns and the Update Parameters should match in order to update using SqlDataSource, then what to do because i have to display all parameters from the table and update only Title ,Body,Author, Categories, Updatedby .... is there any other way to achieve this or an trick...
]
Muhammad Taqi Hassan Bukhari 31-May-14 5:49am    
i tried to pass all parameters into the update parameter, but i have to validate that other than the 6 parameters i specified above should not be update-able, i have made those field read only or invisible, then when the update command occurs, it pass null values to those whose field i set read only or invisible.
"Procedure or function uspUpdateArticle has too many arguments specified."(you are passing 5 parameters value and store procedure wants 6 parameters)
Error already explaining problem.Please debug it.
 
Share this answer
 
Comments
He is passing 6 parameters. See carefully the UpdateParameters.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900