如何从Application传递参数到触发器 [英] How to pass parameters to triggers from Application

查看:70
本文介绍了如何从Application传递参数到触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三张桌子



1. tbllogin - > id ,姓名,pwd



2. tblstudentinfo - > stdid,name,fathername



3. tblstudentinfo_audit - > Id ,行动。



I have three table

1. tbllogin -> id, name, pwd

2. tblstudentinfo -> stdid, name, fathername

3. tblstudentinfo_audit -> Id, Action.

protected void Page_Load(object sender, EventArgs e)
       {
           string id=Session["id"].ToString();
           string name = Session["name"].ToString();
          // Response.Write(id+ " " +name);
       }

       protected void btnsave_Click(object sender, EventArgs e)
       {
           string con = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
           SqlConnection conn = new SqlConnection();
           conn.ConnectionString = con;
           SqlCommand cmd = new SqlCommand();
           cmd.Connection = conn;
           cmd.CommandText = "insert into tblstudentinfo(studentname, fathername) values('"+txtstdname.Text+"', '"+txtfthername.Text+"')";
           cmd.CommandType = CommandType.Text;
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataSet ds = new DataSet();
           da.Fill(ds);


       }





我想发送 id 触发器。





I want to send the id to triggers.

create trigger instblstudentinfo on tblstudentinfo
for insert
as
begin
declare @id int;
declare @changes varchar(100);

select @id=i.id from selected i;
set @changes='Record Inserted';

insert into tblstudentinfo_audit(id, changes) values(@id, @changes)

end





我们怎么能这样做..?



How can we do that..?

推荐答案

插入的数据位于已插入 [ ^ ]表。这应该有效:

The inserted data is in inserted[^] table. This should work:
insert into tblstudentinfo_audit(id, changes) 
select id, @changes from inserted


这篇关于如何从Application传递参数到触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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