Re: How to get RecordsAffected when an exception occurs
From: J L (john_at_marymonte.com)
Date: 03/18/05
- Next message: Raghu: "Re: Why does a DataSet need to have a finalizer?"
- Previous message: Scott M.: "Re: No 'findby' method in strongly typed dataset"
- In reply to: Sean Nolan: "How to get RecordsAffected when an exception occurs"
- Next in thread: Sean Nolan: "Re: How to get RecordsAffected when an exception occurs"
- Reply: Sean Nolan: "Re: How to get RecordsAffected when an exception occurs"
- Messages sorted by: [ date ] [ thread ]
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
>
- Next message: Raghu: "Re: Why does a DataSet need to have a finalizer?"
- Previous message: Scott M.: "Re: No 'findby' method in strongly typed dataset"
- In reply to: Sean Nolan: "How to get RecordsAffected when an exception occurs"
- Next in thread: Sean Nolan: "Re: How to get RecordsAffected when an exception occurs"
- Reply: Sean Nolan: "Re: How to get RecordsAffected when an exception occurs"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|