Possible Duplicate:
SQL: Update a row and returning a column value with 1 query
Get affected rows on ExecuteNonQuery
I have a textbox where the users enter their SQL queries.
On example query could be:
UPDATE customer SET isnew = 1;
Running the above query updates 4 rows, how do I get the '4 rows affected' message that which be returned by SQL Server.
I've tried using InfoMessage but this only returns messages like 'Changed database context to 'databasenamehere' and not the actual rows affected.
SqlCommand.ExecuteNonQuery returns the number of records affects as int:
var command = new SqlCommand("UPDATE customer SET isnew = 1;", conn);
int recordsAffected = command.ExecuteNonQuery();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With