Solved

ASP.Net Gridview Delete with a Stored Procedure

Posted on 2008-06-17
12
1,742 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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
 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 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