Solved

ASP.Net Gridview Delete with a Stored Procedure

Posted on 2008-06-17
12
1,736 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 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

14 Experts available now in Live!

Get 1:1 Help Now