Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,
i have a one stored Procedure which name is 'SP_INSERT'!
within a procedure there are three statements,Like this
SQL
CREATE PROCEDURE SP_INSERT
(
@ID int,
@Name char(20),
@ProductType varchar(20)
)
AS
Begin
insert into Employee(Employee_ID,Employee_Name)values(@ID,@Name)
 
insert into Student(Student_ID,Student_Name)values(@ID,@Name)
 
update Product set Product_ID=@ID where Product_Type=@ProductType
End

Now what i want by using one procedure name like,SP_INSERT i want to call difference types of multiple statements on the difference types of button_click events! so what i have to mention on the button_click events coding for calling the specific sequense of the statements in c#.Net..!

Regards.....!
Posted
Updated 30-Dec-11 7:15am
v4
Comments
anushripatil 30-Dec-11 5:39am    
Hope this is what u were asking

you can pass string from ur code eg. when u want to insert employee pass "Emp", when student pass "stud" ...etc & in ur procedure, u can write the if condition or select case condition to execute your statement
SQL
CREATE PROCEDURE SP_INSERT
(
@ID int,
@Name char(20),
@ProductType varchar(20),
@clickString Varchar(4) --this is just sample name given
)
AS


Hope this is what you were searching.
 
Share this answer
 
v2
Comments
Dnyanesh Wahiley 30-Dec-11 7:21am    
Good hint Anushri....! And Thanx!
thatraja 30-Dec-11 9:50am    
Right, 5!
Wendelius 30-Dec-11 10:25am    
Exactly, 5.
anushripatil 1-Jan-12 23:07pm    
Thanks all :)
 
Share this answer
 
Comments
Dnyanesh Wahiley 30-Dec-11 7:18am    
Good Description!
Wendelius 30-Dec-11 10:25am    
Good link to Mycroft's tip, 5+
thatraja 30-Dec-11 10:51am    
What about mine? :( :cry:
Wendelius 30-Dec-11 13:21pm    
Well, the the credit was for both of you :)
Basically if you want to embed the logic inside a single procedure, you have to pass a parameter which defines what logic path will be applied in your call.

When done properly this parameter should be enumerated in C# and possibly also stored in the database. Also personally I prefer numbers since they are small, easy to enumerate and so on.

But in a rough form you could start from something like:
SQL
CREATE PROCEDURE SP_INSERT
(  @ID int,
  @Name char(20),
  @ProductType varchar(20),
  @Logic int
)
AS
BEGIN
   IF @Logic = 1 BEGIN
      insert into Employee(Employee_ID,Employee_Name)values(@ID,@Name);
   END;
   IF @Logic = 2 BEGIN
      insert into Student(Student_ID,Student_Name)values(@ID,@Name);
   END;
   IF @Logic = 1 OR @Logic = 2 BEGIN
      update Product set Product_ID=@ID where Product_Type=@ProductType;
   END;
END;

Note that this is just a scetch, most likely not following the logic you want.
 
Share this answer
 
Comments
Sridhar Patnayak 30-Dec-11 5:40am    
Very good solution -- my 5
Wendelius 30-Dec-11 5:44am    
Thank you Sridhar.
Dnyanesh Wahiley 30-Dec-11 7:17am    
Efective and Understandable solution...!
Thank you sir
By Dnyanesh Wahiley
Wendelius 30-Dec-11 7:21am    
You're welcome :)
Sridhar Patnayak 30-Dec-11 7:19am    
suggestible, good logic

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