bilpor
bilpor

Reputation: 3931

How to determine if an update was successful

I have the following SP:

ALTER PROCEDURE [dbo].[UpdateOwnerSelectedSkinId]
        (
            @emailAddress VARCHAR(100),
            @skinId int,
            @ownerSkinGroup VARCHAR(100)
        )
    AS
    BEGIN
        SET NOCOUNT ON;
        Update dbo.Owner
         SET  
         SkinId = @skinId, OwnerSkinGroup = @ownerSkinGroup
        WHERE
            EmailAddress = @emailAddress
    END

At the moment if I call this with a valid or invalid email, the value returned by the SP is always 0. How can I determine if the update worked or not.

Upvotes: 0

Views: 941

Answers (1)

kobik
kobik

Reputation: 21252

If "successful" means that any record/s updated, you can set SET NOCOUNT OFF and the number of rows affected will be returned to the client.

In you comments you say you use SqlCommand.ExecuteReader, but your SP does not return any result-set. You should instead use SqlCommand.ExecuteNonQuery which will return the number of rows affected.

Upvotes: 2

Related Questions