PC Review


Reply
Thread Tools Rate Thread

about the ADO.NET property HasErrors

 
 
Tony
Guest
Posts: n/a
 
      16th Dec 2011
Hello!

This property says in a book that I read.the following.
"The HasErrors property returns a Boolean value that indicates wheather any
DataRow objects within the DataSet contains errors. If you're submitting
batches of changes to your database and you've the ContinueUpdateOnError
property of your sqlDataAdapter object to True you should check the
HasErrors property of your DataSet after submitting changes to determine
whether any of the update attempts failed.
The DataTable and DataRow classes also expose a HasError property"

Now I just wonder if somebody can give one example about what can cause the
HasErrors to return true ?

//Tony

 
Reply With Quote
 
 
 
 
Rick Lones
Guest
Posts: n/a
 
      16th Dec 2011
On 12/16/2011 8:48 AM, Tony wrote:
> Hello!
>
> This property says in a book that I read.the following.
> "The HasErrors property returns a Boolean value that indicates wheather any
> DataRow objects within the DataSet contains errors. If you're submitting batches
> of changes to your database and you've the ContinueUpdateOnError property of
> your sqlDataAdapter object to True you should check the HasErrors property of
> your DataSet after submitting changes to determine whether any of the update
> attempts failed.
> The DataTable and DataRow classes also expose a HasError property"
>
> Now I just wonder if somebody can give one example about what can cause the
> HasErrors to return true ?


How about attempting to delete a key that doesn't exist? Or to insert one that
does? Or supplying an invalid value for some particular field type? There are
a lot of ways to screw up a database update, I've invented several myself.
 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      21st Dec 2011
On 12/16/2011 8:48 AM, Tony wrote:
> This property says in a book that I read.the following.
> "The HasErrors property returns a Boolean value that indicates wheather
> any DataRow objects within the DataSet contains errors. If you're
> submitting batches of changes to your database and you've the
> ContinueUpdateOnError property of your sqlDataAdapter object to True you
> should check the HasErrors property of your DataSet after submitting
> changes to determine whether any of the update attempts failed.
> The DataTable and DataRow classes also expose a HasError property"
>
> Now I just wonder if somebody can give one example about what can cause
> the HasErrors to return true ?


If you set your adapters ContinueUpdateOnError property to true,
then adapter Update method will continue in case of errors.

So if you call Update and it needs to update 4 rows and it
updates 2 rows and then something happens (someone trip over
the power cable to the database server, pulls it out and the
server goes down - or something else), then you will see
that your DataSet has HasErrors true, you can find
the DataTable that has HasErrors true and you can find
all DataRow that has HasErrors true to find out what was
updated and what was not.

I don't think it is a widely used feature.

Beginners will ignore this risk (and get burned).

Non-beginners will typical wrap it in a transaction so that
it is either all or nothing.

But just in case someone wanted to code some sophisticated
logic to handle some rows updates some not gracefully, then
the feature is there.

Arne




 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:34 AM.