March 18, 2009 at 1:09 pm
When i insert a single row of data into a sql server table, i am getting an o/p which is telling 3 rows are inserted.
The table is temp19 and there 2 triggers on it as below.
create table temp19(a int, b varchar(100))
create trigger trg_temp19_1 on temp19 for insert
as
update temp19
set b = b + '...'
where a in (select a from inserted)
create trigger trg_temp19_2 on temp19 for insert
as
update temp19
set b = upper(b)
where a in (select a from inserted)
So whenever i insert a single row as below, i am getting value 3 into variable i.
How can i know the exact number of rows inserted in the below code
String strcon = "Data Source = ebommapsqld01\\dev01; database = abc; User Id=abc; password=abc_password; ";
SqlConnection con = new SqlConnection(strcon);
SqlCommand cmd = new SqlCommand("",con);
cmd.CommandText = "insert into temp19 values(5,'eee')";
cmd.CommandType = CommandType.Text ;
con.Open();
int i = cmd.ExecuteNonQuery();
Label1.Text = "the inserted rows are " + i.ToString();
March 18, 2009 at 1:12 pm
Try adding "set nocount on" to the top of each trigger (right after "as").
create trigger MyTrigger on dbo.MyTable
for insert
as
set nocount on; -- Right Here
...
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
March 18, 2009 at 3:02 pm
Thanks for your reply. It worked. 😎
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply