Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0 .NET4
i have created one stored procedure in which i performed insert query below is the code
 
ALTER PROCEDURE sp1
/*
(
@parameter1 int = 5,
@parameter2 datatype OUTPUT
)
*/
(

@name nvarchar(50),
@age nvarchar(50)
)
 

AS
/* SET NOCOUNT ON */
insert into customer values(@name,@age)
RETURN
 

 

now what i want is that i could perform update and delete and select query in the same stored procedure.....................and in front end when i click on select, insert, update , delete button its respective operation should work taking from one stored procedure.....
 

how can i achieve this..............
regards,
Posted 10-Jan-13 1:34am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

CREATE PROCEDURE ASampleProcedure
(
@id int,
@name varchar(50),
@age int,
@option int
)
AS
BEGIN
if @option = 1
BEGIN
--insert record
insert into customer values (@name, @age)
select 'Record inserted.' as Result
END
else
BEGIN
if @option = 2
BEGIN
--update record
update customer set [Name] = @name, [Age] = @age where ID = @id
select 'Record updated.' as Result
END
else
BEGIN
--deleterecord
delete from customer where ID = @id
select 'Record deleted.' as Result
END
END
END
 
From your front end pass parameters and option (1,2 or 3) This single procedure will perform all the operations.
  Permalink  
Comments
vinodkumarnie at 25-Jan-13 6:24am
   
Remember that - you have to pass all parameter from your code behind in each click with respective option value....
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

yes, you can do it you can pass one more parameter called @Trans_Type varchar type
and the call that parameter in page itself.
 
ex
 
IF @Trans_Type='select'
--select query
else if @trans_type='delete'
--delete query
else if @trans_type='insert'
--insert query
 
like that you can use it no problem in that
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 7,280
1 Sergey Alexandrovich Kryukov 6,059
2 Maciej Los 3,579
3 Peter Leow 3,383
4 CHill60 2,522


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100