我想知道如何在使用 SqlDataAdapter
类时获取受影响的行数。此行是否返回编号。受影响的行数?
adapter.UpdateCommand = command;
最佳答案
adapter.UpdateCommand
不执行查询,它只是为更新设置 SqlCommand 并且不返回任何内容。
SqlCommand.ExecuteNonQuery
仅返回更新语句中受影响的行数:
int affectedRows = adapter.UpdateCommand.ExecuteNonQuery();
adapter.Update
int affectedRows = adapter.Update(dataSet);
SqlDataAdapter.UpdateCommand 的文档:
Gets or sets a Transact-SQL statement or stored procedure used to update records in the data source.
SqlCommand.ExecuteNonQuery 的文档
Executes a Transact-SQL statement against the connection and returns the number of rows affected.
关于c# - 获取 SQL 表的受影响行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38505011/