Solved

ASP.Net Gridview Delete with a Stored Procedure

Posted on 2008-06-17
12
1,739 Views
Last Modified: 2012-08-13
Procedure 'sp_DeleteZTest' expects parameter '@id', which was not supplied.

I am getting the above error message for my GridView Delete Stored procedure below:


Create Procedure dbo.sp_DeleteZTest
@id int
as
delete ZTest where id = @id

It must be a problem on the GridView side.

Thanks.

0
Comment
Question by:drlewicki
  • 7
  • 5
12 Comments
 
LVL 22

Expert Comment

by:prairiedog
ID: 21806595
>>>It must be a problem on the GridView side.
Then what do your GridView look like?
How do you process the deletion in your GridView?
0
 

Author Comment

by:drlewicki
ID: 21806891
I have it configured to use the stored procedure. Is this what you are asking?
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 21806927
Without source code, it will be like shooting in the dark. How can we possibly help you?
0
 

Author Comment

by:drlewicki
ID: 21807357
       <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            DeleteCommand="sp_DeleteZTest" SelectCommand="sp_SelectZTest" UpdateCommand="sp_UpdateZTest2" UpdateCommandType="StoredProcedure" DeleteCommandType="StoredProcedure" InsertCommand="sp_InsertZTest" InsertCommandType="StoredProcedure" SelectCommandType="StoredProcedure">
            <DeleteParameters>
                <asp:Parameter Name="id" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="id" Type="Int32" />
                <asp:Parameter Name="FirstName" Type="String" />
                <asp:Parameter Name="LastName" Type="String" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="FirstName" Type="String" />
                <asp:Parameter Name="LastName" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>
0
 

Author Comment

by:drlewicki
ID: 21807427
Here's the full source of the Page.
GridView.txt
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 21807564
I don't see any place where you assign value to @id, that is the cause of the problem.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:drlewicki
ID: 21807714
Shouldn't that be automatic? If I go to delete a row in the gridview, shouldn't @id be assigned to what it is in the gridview?
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 21807774
That would be ver nice...but unfortunatelly it does not work that way.
0
 

Author Comment

by:drlewicki
ID: 21807799
That's the way the update works (and the update works), it picks up the id from the grid. See below.

CREATE PROCEDURE dbo.sp_UpdateZTest2
      (
      @id integer,
      @FirstName varchar(15),
      @LastName varchar(15)
      )
AS
      /* SET NOCOUNT ON */
      UPDATE    ZTest
      SET              
            FirstName = @FirstName,
            LastName = @LastName
      WHERE     (id = @id)
      RETURN

GO
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 21807865
>>>>>That's the way the update works (and the update works), it picks up the id from the grid.
That is interesting. Without any code-behind at all?
0
 

Accepted Solution

by:
drlewicki earned 0 total points
ID: 21826470
yes. What way are you suggesting that I code this? And where - in the code-behind?
0
 

Author Comment

by:drlewicki
ID: 22137879
use DataKeyNames = "ID" in the source for the gridview.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 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

17 Experts available now in Live!

Get 1:1 Help Now