I would like to know how can I get the count of affected rows when using the SqlDataAdapter
class. Does this line return the no. of affected rows?
adapter.UpdateCommand = command;
I would like to know how can I get the count of affected rows when using the SqlDataAdapter
class. Does this line return the no. of affected rows?
adapter.UpdateCommand = command;
adapter.UpdateCommand
doesn't execute the query, it just sets the SqlCommand for Updates and it doesn't return anything.
SqlCommand.ExecuteNonQuery
returns just the number or affected rows in the update statement:
int affectedRows = adapter.UpdateCommand.ExecuteNonQuery();
Also you have the same information returned by adapter.Update
int affectedRows = adapter.Update(dataSet);
Docs for SqlDataAdapter.UpdateCommand:
Gets or sets a Transact-SQL statement or stored procedure used to update records in the data source.
Docs for SqlCommand.ExecuteNonQuery
Executes a Transact-SQL statement against the connection and returns the number of rows affected.
ExecuteNonQuery - returns the number of rows affected.
SqlCommand comm;
// other codes
int numberOfRecords = comm.ExecuteNonQuery();