Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.Net Gridview Delete with a Stored Procedure

Posted on 2008-06-17
12
Medium Priority
?
1,750 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

610 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