Stored Procedure..........
USE [myDatabase]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[sp_main]
(
@id int = 0,
@action varchar(50) = NULL,
@firstname varchar(50) = NULL,
@lastname varchar(50) = NULL,
@email varchar(50) = NULL,
@state varchar(50) = NULL,
@city varchar(50) = NULL,
@mob varchar(50) = NULL,
@dep varchar(50) = NULL,
@dob date = NULL,
@salary int = 0
)
as
begin
if @action = 'insert'
begin
insert into empDetail values (@firstname, @lastname, @email, @state, @city, @mob, @dep)
declare @empId int
set @empId = SCOPE_IDENTITY()
insert into empDpartment values(@empId, @firstname, @dep, @dob, @salary)
end
if @action = 'delete'
begin
delete from empDetail where id = @id
end
if @action = 'update'
begin
update empDetail set fname = @firstname, lname = @lastname, email = @email, state = @state, city = @city, mob = @mob, dep = @dep where id = @id
update empDpartment set fname = @firstname, department = @dep, dob = @dob, salary = @salary where empID = @id
end
if @action = 'select'
begin
select * from empDetail
end
end
Code for deleting data........
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int id = int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
cmd = new SqlCommand("sp_main", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", id);
cmd.Parameters.AddWithValue("@action", "delete");
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}<b><b><b><b><b><b></b></b></b></b></b></b>
What I have tried:
Anybody can help me....I don't have an idea, how to solve this error.