Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning rows affected from an SQL UPDATE statement [duplicate]

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.

like image 376
bluenose1970 Avatar asked May 17 '26 01:05

bluenose1970


1 Answers

SqlCommand.ExecuteNonQuery returns the number of records affects as int:

var command = new SqlCommand("UPDATE customer SET isnew = 1;", conn);
int recordsAffected = command.ExecuteNonQuery();
like image 114
Eren Ersönmez Avatar answered May 18 '26 13:05

Eren Ersönmez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!