Re: How to get RecordsAffected when an exception occurs

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: J L (john_at_marymonte.com)
Date: 03/18/05


Date: Fri, 18 Mar 2005 11:09:37 -0800

Why not handle it in a transaction and roll back on the exception.
That way you know all or nothing was affected?

John

On Fri, 18 Mar 2005 10:56:53 -0600, "Sean Nolan"
<seann@imgno%spaminc.com> wrote:

>If I have this code
>
>SqlCommand cmd = new SqlCommand("<text with multiple inserts>", conn);
>int recs = 0;
>try
>{
> recs = cmd.ExecuteNonQuery();
>}
>catch (SqlException exc)
>{
> //whatever
>}
>
>If an exception occurs the value obviously isn't assigned to my variable
>recs, however records may well have been affected even when an exception
>occurs. The problem is that I cannot find any way to find out how many
>records were affected. When I debug this, I can see that the SqlCommand
>class has an internal field that correctly shows how many records were
>affected, but for some reason the SqlCommand class does not have an
>accessible RecordsAffected property that shows that value, so you can't get
>to it in regular code.
>
>This seems like a design flaw in the SqlCommand class?
>
>Sean
>



Relevant Pages

  • How to get RecordsAffected when an exception occurs
    ... catch (SqlException exc) ... If an exception occurs the value obviously isn't assigned to my variable ... This seems like a design flaw in the SqlCommand class? ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: How to get RecordsAffected when an exception occurs
    ... I don't want to roll back - I just want to know how many of the ... seems like the SqlCommand class should have a RecordsAffected property. ... > Why not handle it in a transaction and roll back on the exception. ... >>to it in regular code. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: How to get RecordsAffected when an exception occurs
    ... A simple work-around would be to use the SELECT @@ROWCOUNT to get the right ... "Sean Nolan" wrote in message ... > If an exception occurs the value obviously isn't assigned to my variable ... > This seems like a design flaw in the SqlCommand class? ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: What on earth do I do with this?
    ... I own is 100 percent cotton or wool. ... Lycra is the only exception I make, ... John, you're too funny -- and it's a good thing I wasn't ... drinking my coffee when I read this, or I'd have been spewing it all ...
    (rec.crafts.textiles.quilting)
  • Re: I want to get an english name which will the only one in the world. Any possible?
    ... countries I have visited, although its pronunciation varies ... (One exception was Macedonia, ... However, if your name is John or Henry, you are very likely to be ...
    (alt.usage.english)