Click here to Skip to main content
15,900,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have three table

1. tbllogin -> id, name, pwd

2. tblstudentinfo -> stdid, name, fathername

3. tblstudentinfo_audit -> Id, Action.

C#
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);


       }


I want to send the id to triggers.

SQL
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..?
Posted

1 solution

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900