通过使用一个存储过程Name调用Multiple语句. [英] By using one Stored procedure Name calling the Multiple statements..!

查看:44
本文介绍了通过使用一个存储过程Name调用Multiple语句.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,
我有一个存储过程,名称为"SP_INSERT"!
一个过程中有三个语句,就像这样

Hi Friends,
i have a one stored Procedure which name is ''SP_INSERT''!
within a procedure there are three statements,Like this

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


现在我想通过使用一个过程名称,例如SP_INSERT,我想在button_click事件的不同类型上调用多个语句的不同类型!因此,我必须在button_click事件编码中提及的内容,以调用c#.Net中的语句的特定顺序.

问候..... !!


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.....!

推荐答案

您可以从您的代码中传递字符串,例如.当您要插入员工通行证"Emp"时,当学生通行证"stud"时... etc&在您的过程中,您可以编写if条件或select case条件以执行您的语句
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
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.


尝试此技巧/窍门

将插入/更新合并到一个过程 [
Try this Tip/Trick

Combining Insert/Update to one Procedure[^]


基本上,如果要将逻辑嵌入到单个过程中,则必须传递一个参数,该参数定义将在调用中应用的逻辑路径.

正确完成此参数后,应在C#中枚举该参数,并且可能还应将其存储在数据库中.我个人也更喜欢数字,因为它们很小,易于枚举等等.

但以粗略的形式,您可以从以下内容开始:
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:
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;


请注意,这只是一个scetch,很可能不遵循您想要的逻辑.


Note that this is just a scetch, most likely not following the logic you want.


这篇关于通过使用一个存储过程Name调用Multiple语句.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆