Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
aspx code
if (e.CommandName == "delete")
{

Button btn = (Button)e.CommandSource;
GridViewRow grdrow = ((GridViewRow)btn.NamingContainer);
int empid = Convert.ToInt32(GridView1.DataKeys[grdrow.RowIndex].Values["id"].ToString());
//string str = "delete from text where id=" + empid + "";
// string str = "delete From Employee where id=" + empid + "";
cmd = new SqlCommand("deleteFromTable", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter sp1 = cmd.Parameters.AddWithValue("@empid",empid);
con.Open();
// cmd = new SqlCommand(str, con);
cmd.ExecuteNonQuery();
Response.Write("<script>alert('Record deleted secussfully...')</script>");
con.Close();
Show();

}

storedprocedure

Use Test
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <author,,name>
-- Create date: <create>
-- Description: <description,,>

Create Procedure [dbo].[deleteFromTable]
@FirstName varchar(50),
@MiddleName varchar(50),
@LastName varchar(50),
@empid int
As
Begin
Delete from Employee where id=@empid
End

What I have tried:

on delete it says @FirstName parameter is required which is not supplied
Posted
Updated 7-Jun-16 2:26am
Comments
VR Karthikeyan 7-Jun-16 6:25am    
just remove unwanted parameters in stored procedure, here the following parameters
@FirstName varchar(50),
@MiddleName varchar(50),
@LastName varchar(50),
are not needed. so delete it and try again.

Hi
Delete first three parameter these are additional parameter
@FirstName varchar(50),
@MiddleName varchar(50),
@LastName varchar(50),

Because when you are sending input from C# code you are sending only one parameter to procedure and actual definition of procedure contains 4 input parameter.
 
Share this answer
 
Comments
Member 10549697 7-Jun-16 6:32am    
Yes..Thank You...
You are passing only one parameter from code and there are 4 parameters in store procedure.you only need to pass 1 paramater employeeid. remove other parameters

sol : -

SQL
Create Procedure [dbo].[deleteFromTable]
@empid int
As
Begin
Delete from Employee where id=@empid
End
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900