C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » SQL Server »

doubt about stored procedure


Posted Date: 20 Aug 2008      Posted By: MuthuKumaresan      Member Level: Silver     Points: 1   Responses: 2



Is any possible for edit and delete and insert and update using single procedure
ple send source code for that





Responses

Author: Nagarajan.L    20 Aug 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 6

Hi,
we can do all in one sp. i given one sp below for sample.

sp :

create procedure allInOne
@action char(1),
@id int=null,
@name nvarchar(50)=null

as

if(@action='I')
begin
insert into tblTest (id,name) values(@id,@name)
end
else if(@action='U')
begin
update tblTest set name=@name where id=@id
end
else if(@action='D')
begin
delete from tblTest where id=@id
end

here tblTest is a table Name.
and action parameter
if i means Insert
U means Update
D means Delete

i take two field in my example id and name. now i hope u can do ur need usig this example.


thanks
Nagarajan.L



Author: vipul    20 Aug 2008Member Level: DiamondRating: 2 out of 52 out of 5     Points: 5

hi,
it is possible but it is complicated you have to check variable to perform operation like this way.

create procedure test
(
@Action varcahr(10) // From the c# code you passed 'Insert', 'Update', 'Delete'
//then Your Data to pass for insert but here allow null
@column1 varchar(50)=null,
@cloumn int =0
)
as
begin
if @Action = 'Insert'
begin
// insert data
end
else if @Action = 'Update'
begin
// update data
end
else if @Action = 'Delete'
begin
// Update Data
end
end

vipul,
http://dongavipul.blogspot.com

Please Rate This Answer If They Helpful

Thanks & Regards
Patel Vipul



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Renaming a table in SQL
Previous : DTS Package
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use