Getting RowCounts for Multiple Statements

  • Thread starter Thread starter Ashton
  • Start date Start date
A

Ashton

I am trying to execute several DML statements in a single call to an ADO.NET
SqlCommand object, ie.

update table1 set column1 = x
update table2 set column2 = y

I am wanting to get the rows affected for each update statement, ie. 10 rows
for table1, 20 rows for table2, but the RowsAffected only gives me the total
for the statement. Is there any way to get the records affected broken out
by statement.

I tried capturing the InfoMessages from the SqlConnection and turning set
nocount off, but it doesn't provide any messages.

Any ideas?

Thanks,

Ashton Hobbs
 
Don't think this is possible in .NET 1.1, however in .NET 2.0 there is a new
event on SqlCommand called as StatementCompleted, which is called as many
times as many batched queries you have and that indeed does show up a split
of individually affected rows.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
 
Back
Top