about the ADO.NET property HasErrors

T

Tony

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
 
R

Rick Lones

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. :)
 
A

Arne Vajhøj

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top