drlewicki
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.
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.
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?
ASKER
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Northwin dConnectio nString %>"
DeleteCommand="sp_DeleteZT est" SelectCommand="sp_SelectZT est" UpdateCommand="sp_UpdateZT est2" UpdateCommandType="StoredP rocedure" DeleteCommandType="StoredP rocedure" InsertCommand="sp_InsertZT est" InsertCommandType="StoredP rocedure" SelectCommandType="StoredP rocedure">
<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>
DeleteCommand="sp_DeleteZT
<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>
ASKER
Here's the full source of the Page.
GridView.txt
GridView.txt
I don't see any place where you assign value to @id, that is the cause of the problem.
ASKER
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.
ASKER
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
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?
That is interesting. Without any code-behind at all?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
use DataKeyNames = "ID" in the source for the gridview.
Then what do your GridView look like?
How do you process the deletion in your GridView?