34,590
社区成员
发帖
与我相关
我的任务
分享
USE SampleDB
GO
CREATE TABLE TTestTri(ID int);
GO
CREATE TRIGGER tr_cTTestTri ON TTestTri
AFTER INSERT
AS
RAISERROR('Error:2',16,1)
go
C#:
try
{
SqlConnection thisConn = new SqlConnection(@"Server=(Local);Database=SampleDB;Integrated Security=True");
SqlCommand thisComm = new SqlCommand("INSERT INTO dbo.TTestTri(ID)VALUES(2);", thisConn);
thisConn.Open();
thisComm.ExecuteScalar();
thisConn.Close();
}
catch(Exception ex) {
Console.WriteLine(ex.Message);
}
Console.ReadKey();