用C#如何调用sql server2000触发器?

用C#如何调用sql server2000触发器?
2025-03-21 08:56:34
推荐回答(3个)
回答1:

--1、在Visual studio 中完成代码C#代码
--2、修改数据库的权限
ALTER DATABASE AdventureWorks SET TRUSTWORTHY ON
--3
sp_configure Clr_enabled , 1
--4
reconfigure
--5
create assembly CalcSalAssemble From 'F:\EmployeePay\EmployeePay\bin\Debug\EmployeePay.dll' //你写的程序的Debug 的 xx.dll地址
With Permission_set = UNSAFE
--6
sql 程序

例:--步骤
--1、完成代码
/*
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using Microsoft.SqlServer.Server;

namespace EmployeePay
{
public class Pay
{
[Microsoft.SqlServer.Server.SqlFunction(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)]
public static SqlString calcSalary(SqlString emp)
{
//SqlConnection connection = new SqlConnection(@"Data Source=HYIT\SQLEXPRESS;Initial Catalog=AdventureWorks;User ID=sa;Password=as");
SqlConnection connection = new SqlConnection(@"context connection = true");
SqlString sr = new SqlString();
connection.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = connection;
cmd.CommandText = "Select distinct employeeid,[rate],[payfrequency] from HumanResources.EmployeePayHistory where ratechangedate <= modifieddate and employeeid = " + emp.ToString ();
SqlDataReader dr;
dr = cmd.ExecuteReader();
while (dr.Read())
{
sr = Convert .ToString (Convert .ToDouble (dr[1].ToString ())*Convert .ToDouble (dr[2].ToString ())*22);
}
dr.Close();
connection.Close();
return sr;
}
}
}*/
--2、修改数据库的权限
ALTER DATABASE AdventureWorks SET TRUSTWORTHY ON
--3
sp_configure Clr_enabled , 1
--4
reconfigure
--5
create assembly CalcSalAssemble From 'F:\EmployeePay\EmployeePay\bin\Debug\EmployeePay.dll'
With Permission_set = UNSAFE
--6
Create Function SalaryCalculation(@EmpID as nVarchar(3))
returns nVarchar(10)
As External Name CalcSalAssemble.[EmployeePay.Pay].calcSalary
--7
select dbo.SalaryCalculation('23')

回答2:

触发器是运行SQL语句的时候,系统自动运行的,要不怎么叫触发器。触发器是不用人为执行的。
你说的调用是调用存储过程或函数吧。

回答3:

触发器:准确的来说触发器是你在更新或者操作某个数据时,而执行的一段程序。比如:你写一段代码当删除每个员工的姓名时,也删除该员工的所有信息。这就是叫做触发器。
所以触发器是不用调用的。

这是我个人的理解,希望对你有帮助!