C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




doubt about stored procedure


Posted Date: 20 Aug 2008      Total Responses: 2

Posted By: MuthuKumaresan       Member Level: Silver     Points: 1



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:     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:     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

Patel Vipul
Web Developer
Ahmedabad ( Gujarat )



Post Reply
You must Sign In to post a response.
Next : Renaming a table in SQL
Previous : DTS Package
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use