Link to home
Start Free TrialLog in
Avatar of drlewicki
drlewickiFlag for United States of America

asked on

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.

Avatar of prairiedog
prairiedog
Flag of United States of America image

>>>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?
Avatar of drlewicki

ASKER

I have it configured to use the stored procedure. Is this what you are asking?
Without source code, it will be like shooting in the dark. How can we possibly help you?
       <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>
Here's the full source of the Page.
GridView.txt
I don't see any place where you assign value to @id, that is the cause of the problem.
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?
That would be ver nice...but unfortunatelly it does not work that way.
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
>>>>>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?
ASKER CERTIFIED SOLUTION
Avatar of drlewicki
drlewicki
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
use DataKeyNames = "ID" in the source for the gridview.