ASP.Net Gridview Delete with a Stored Procedure

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.

drlewickiAsked:
Who is Participating?
 
drlewickiConnect With a Mentor Author Commented:
yes. What way are you suggesting that I code this? And where - in the code-behind?
0
 
prairiedogCommented:
>>>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
 
drlewickiAuthor Commented:
I have it configured to use the stored procedure. Is this what you are asking?
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
prairiedogCommented:
Without source code, it will be like shooting in the dark. How can we possibly help you?
0
 
drlewickiAuthor Commented:
       <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
 
drlewickiAuthor Commented:
Here's the full source of the Page.
GridView.txt
0
 
prairiedogCommented:
I don't see any place where you assign value to @id, that is the cause of the problem.
0
 
drlewickiAuthor Commented:
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
 
prairiedogCommented:
That would be ver nice...but unfortunatelly it does not work that way.
0
 
drlewickiAuthor Commented:
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
 
prairiedogCommented:
>>>>>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
 
drlewickiAuthor Commented:
use DataKeyNames = "ID" in the source for the gridview.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.