1

I have the following code using microsoft enterprise library 5:

Database database = DatabaseFactory.CreateDatabase("myConStr");
int rowsAffected = database.ExecuteNonQuery("[DeleteCustomer]", cboCustomers.SelectedItem.ToString());

The myConStr is correctly defined in the app.config (it works for other EL-based queries). The DeleteCustomer SP is defined as:

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

In the documentation of the ExecuteNonQuery metod the result is said to return the number of rows affected.

However, I always get the result "-1", even if the deletion works fine. What's wrong? What can I do to get the number of deleted records?

Thanks, Lucian

4

1 回答 1

3

“当 SET NOCOUNT 为 ON 时,不返回计数(指示受 Transact-SQL 语句影响的行数)。”

于 2010-11-11T18:48:14.640 回答