Getting RowCounts for Multiple Statements

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
 
S

Sahil Malik

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top