DataRow throwing exceptions.... but not setting HasErrors?

  • Thread starter Thread starter Martin Z
  • Start date Start date
M

Martin Z

I'm just learning ADO.NET 1.1 and I'm getting some real stinkers.

I've got a wonderful screwup going on - I'm loading my datatable with a
new datarow. I used BeginLoadData before I added the row because I
need to bind to that row in the datatable. I the use "BeginEdit" on
the row so that I can leave a mark to cancel back to later if
necessary, and make the changes to the row, and then I call "EndEdit"
on the datarow to validate the changes.

As expected for the garbage data I entered in, it throws a
DataException. What blows my mind is that it DOESN'T set the HasErrors
information, or any other error info. So I have nothing but the
friggin' exception to show the user. What do I do? How do I work with
a databound datarow in such a way that I can get useful error info?
 
Martin,

The least thing is to set it inside a try catch block.
Be aware that binding keeps its rules. Even more if you use a strongly typed
dataset.
By instance relations and all other constrains have to be save inside what
you add.

The "if" is the most excelent instruction to test that.

The haserrors is set as you have by instance given the instruction to the
dataadapter to ignore errors. Than the errors are set at update time in the
rows but there is not any error thrown, the complete table is processed,
except the rows which have errors..

I hope this helps,

Cor
 
Of course I have it in a try-catch-block. Of course I use "If". I'm
not talking about basic programming here - I'm asking about the
minimally-documented behaviour of the ADO.Net modules. The problem is
that there is completely inconsistent behaviour all across ADO.NET -
depending on the order I do things in, the datatable will throw an
exception

a) when I attempt to set the data within the row.
b) when I attempt to call EndEdit().
c) when I attempt to call EndLoadData().

But there is no sensible rhyme or reason to it - and EndEdit does not
set the HasErrors flag, so when EndEdit fails, I can't find the
problem. Since BeginEdit is called implicitly on any change, there is
no reason that sometimes it will fail on EndEdit and sometimes on
setting the invalid data... and other times it will accept it on
EndData and fail on EndLoadData.

Does anybody know how this mess of Begin and Ends works? I just want
to add a blank row to the table so I can bind to it, edit the bound
row, and then check for errors if the user clicks "accept" or revert
them if he clicks "cancel" - why is such a simple concept so
horrifically complicated?
 

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

Back
Top