嗨,我已经创建了一个触发器如何在C#中使用触发器 [英] Hi i have Created One Trigger How to use the Trigger in C#
本文介绍了嗨,我已经创建了一个触发器如何在C#中使用触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的弗里德斯,
在这里,我在SqlServer中编写了一个触发器概念,我想知道如何
使用Asp.net在c#中调用触发器
我在Sql Server中的触发器:
Dear Frieds,
Here i have Written one Trigger Concept in SqlServer and I want to Know how
to Call the Triggers in c# with Asp.net
My Triggers in Sql server:
ALTER trigger tr_insert
on SchoolDetailsInfo
after insert
as
begin
declare @intSchoolId int= null
declare @SchoolName varchar(30)=null
declare @PrincipleName varchar(30)=null
declare @LandlineNo varchar(30)=null
declare @MobileNo varchar(30)=null
declare @Address varchar(30)=null
declare @DateofBirth varchar(30)=null
declare @Flag varchar = null
select @intSchoolId=intSchoolId from inserted
select @SchoolName =strSchoolName from inserted
select @PrincipleName=strPrincipleName from inserted
select @LandlineNo =strLandLine from inserted
select @MobileNo=strMobileNo from inserted
select @Address =strAddress from inserted
select @DateofBirth =intdate from inserted
update SchoolDetailsInfo
set strSchoolName='anil' where intSchoolId!=@intSchoolId
end
所以现在我想用c#
在asp.net中调用触发器
问候,
Anilkumar.D
So now i want to call the Trigger in asp.net with c#
Regards,
Anilkumar.D
推荐答案
您不能直接从任何代码中调用触发器.当为其创建触发器的事件发生时,触发器由数据库执行.在您的情况下,由于它是AFTER INSERT触发器,因此将在创建触发器的表上发生插入之后执行该触发器.您可以使用ADO.NET将数据插入表中以运行触发器代码.
You cannot call the trigger directly from any code. The trigger is executed by the database when the event for which it is created happens. In your case, since it is an AFTER INSERT trigger, it will be executed after an insert happens on the table in which the trigger is created. You can insert data into the table using ADO.NET to run the trigger code.
SqlCommand comm = new SqlCommand("INSERT INTO Table1 (Col1, Col2, Col3) VALUES (@Col1, @Col2, @Col3)", connection);
comm.Parameters.AddWithValue("@Col1", Col1Value);
comm.Parameters.AddWithValue("@Col2", Col2Value);
comm.Parameters.AddWithValue("@Col3", Col3Value);
comm.ExecuteNonQuery();
您不能使用或使用C#调用触发器.
触发自动执行以响应特定表或数据库视图中的某些事件.
You can not use or call trigger using C#.
Trigger automatically executed in response to certain events on a particular table or view in a database.
这篇关于嗨,我已经创建了一个触发器如何在C#中使用触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文