我使用microsoft enterprise library 5获得以下代码:
Database database = DatabaseFactory.CreateDatabase("myConStr");
int rowsAffected = database.ExecuteNonQuery("[DeleteCustomer]", cboCustomers.SelectedItem.ToString());
myConStr在app.config中正确定义(适用于其他基于EL的查询)。 DeleteCustomer SP定义为:
CREATE PROCEDURE DeleteCustomer
@CustomerID nchar(5)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
delete from dbo.Customers
where CustomerID = @CustomerID
END
在ExecuteNonQuery metod的文档中,结果被称为返回受影响的行数。
但是,我总是得到结果“-1”,即使删除工作正常。怎么了?如何获取已删除记录的数量?
谢谢, 卢西恩
答案 0 :(得分:3)
“当SET NOCOUNT为ON时,不返回计数(表示受Transact-SQL语句影响的行数)。”