Handling rowerrors and deleted rows

G

Guest

Hi Guys,
I have to warn that I am a .Net novice and in fact don't use ADO.NET in the
"traditional" way but via access to a Progress (www.progress.com) AppServer
via proxies that they allow you to build.

I have been playing with creating a program where I get data into a dataset
via this method. I then update it in a datagrid. Next I get the changes and
send them back to the server to update and lastly I get any updates to that
dataset (or errors back) and try to handle them (normally just merge to
orginial dataset).

The problem that I am facing is how to handle a case where I have errors and
successfully deleted rows in the one returned dataset. If I merge the results
and then run AcceptChanges on the dataset, it shows the error but doesn't
leave it as needing work. I found that working through the rows and accepting
changes on rows with out errors worked until I hit successfully deleted rows.
When I accepted changes on these, it changed the dataset and stopped me
looping through the dataset (get an exception that the collection had changed
or something).

I walked through the rows sort of like this:
dim row as datarow
for each row in dataset.datatable.rows

Can anyone suggest a better way of doing this?

TIA
Molly
 
S

Sahil Malik

I am not quite familiar with progress, but I assume that is similar to a
database abstraction layer or something on those lines.

And if I understood your problem correctly, basically what you are trying to
do is, you get a dataset back after some operation around the d/b, and you
need to merge it with your front end dataset, which is bound to a datagrid,
to basically show the updates/added rows/deleted rows properly.

To gain a good insight into why you are getting the error, every row
maintains versions, and as you were IEnumerating over the rows collection,
the collection changed hence rendering the enumerator to be invalid,
therefore you got the error.

An easy way to get around this problem could be to use the DataViewRowState
enum to filter out Deleted rows etc. individually, and to treat each case
individually. As a matter of fact, (without looking at your code), chances
are high that you should be able to use Dataset.Merge for every operation
other than delete - for which you have to enumerate manually.

I would recommend reading a good book on ADO.NET; I've written one or there
are quite a few good intelligent folks on this newsgroup as well (but they
can't read for you). I feel you would be able to reach the best solution
only after knowing how a dataset works in it's insides - and it is actually
quite interesting - recommended interesting reading !! :)

Obviously another hammer approach is to reload the dataset and discard the
original dataset - but I assume that might not be practicable in your case
or you would have already done it.

- Sahil Malik
You can reach me thru my blog at
http://www.dotnetjunkies.com/weblog/sahilmalik
 
G

Guest

Hi Sahil,
Thanks for the reply, I might add my code and a little explaination of
what's in each dataset and this may help people to help me on this community
forum. I agree that a good ADO.NET book may help, but most are written around
the idea of getting data out of a SQL Server database (as this is probably
the most used way of access) and this doesn't seem to fit the model I am
using. I guess this model fits closest to using Webservices.

TIA
Molly
 
G

Guest

Hi Sahil,
Thanks for the suggestion, you are right a book would good (no freebies?
Just kidding). Any one not just trying to flog their own book care to comment?

Molly
 
G

Guest

Fair point, I might be being a bit hard. I am use to a different community
and a different level of answers (i.e. The Progress community). I also accept
that having the code that I am using and a fuller explaination of the dataset
state coming back from progress, you might be able to give me more insight
into my own failings.

Sahil, please accept my appology for my flipent remark. I should really be
thanking you for taking the time to give me any sort of answer.

TIA
Molly
PS. What is your book called?
 
A

Alex Homer

I guess I have to be careful because I am the author of a couple of books
that cover the topics of reconciling update errors with a DataSet. However,
in mitigation, the samples are available online to run and view the source,
and can be downloaded for free. If you find that they answer your questions,
I won't complain if you decid to buy the book as well.

Issues in catching update errors are demonstrated at:
http://www.daveandal.net/books/8900/08_to_11_Data_Management/data04/default.htm

An application that does remote updates over the Web and allows
concurrentuupdate errors to be reconciled can be found at:
http://www.daveandal.net/books/4923/customer-orders.htm
http://www.daveandal.net/books/4923/updating-data/

Drop me a line if you want to clarify anything about these...
 
S

Sahil Malik

LOL ALEX .. Hey I'm reading your ASP.NET 2.0 book these days. I'm excited;
I'll be using all that I am learning on a website I will be architecting
soon.

Molly, it's allright, my intention was to help and the message is clear -
you have to read a book - either mine; because I know my book explains what
you need - or some other - plenty of folks other than me have written books
on ADO.NET, go to borders or some bookstore and pick one. Other than the one
I have written, I would recommend David Sceppa's book - he is on these
newsgroups too at times. For my book, you can search amazon.com for my name.

Again, read a book, especially ADO.NET which is not changing a LOT in .NET
2.0 (few things added thats all). It is a good investment of time.

- Sahil Malik
You can reach me thru my blog http://www.dotnetjunkies.com/weblog/sahilmalik
 
A

Alex Homer

Hey Sahil - good to see you so active on the lists.

As an author, I'm bound to say that reading a book is the way to go <g>, but
seriously it is true that many times you can't really get a view of what is
going on just from the code. I don't like to remember the many hours we
spent playing with merging and updating DataSets to figure out the best
approach for error reconciliation. It really isn't intuitive in V1.x, though
(as you'll have seen by now) the changes in v2.0 make it all much easier!
 
G

Guest

Hi Guys,
Thanks for the help. I have got further on this and it has turned out a
little more complicated then I thought it would be. I found apart from
getting the .Net datasets mergered correctly, I also have to check the errors
reported in the rowerror (these are passed back from Progress) and see what
the problem is (I have seen a lot of talk of handling errors via exceptions
throw but because of the nature of the environment this doesn't seem to
work).

I am currently thinking through all the possible errors caused by loosely
updating on the client (i.e. What do I do if I go to delete a row on the
client and the values have changed on the server? What do I do if I go to add
on the client and theres already a record on the server. What do I do if I go
to change a value and the record is deleted on the server. If the record has
changed since I got it, do I want to accept the server changes or store my
client changes and then try to reapply them, etc (think I am waffling)).

The big problem that I believe I solved was in the way that I was walking
through the rows, when I did an acceptchanges on a deleted row, the
collection changed and an error was thrown. The fix to this issue was to
accept these changes on there own getting these rows with the select option
where you filter on row state or deleted. I believe this is what you where
hinting at Sahil, so a great thanks for you help.

I have taken on board that an ADO.NET book would be helpful and will see if
I can get one either for work collection or at home (very unlikely due to the
amount of work I do on .Net).

TIA
Molly
 
S

Sahil Malik

Hey Molly,

About --
------------------------------------------------------------------------
I am currently thinking through all the possible errors caused by loosely
updating on the client (i.e. What do I do if I go to delete a row on the
client and the values have changed on the server? What do I do if I go to
add
on the client and theres already a record on the server. What do I do if I
go
to change a value and the record is deleted on the server. If the record has
changed since I got it, do I want to accept the server changes or store my
client changes and then try to reapply them, etc (think I am waffling)).
------------------------------------------------------------------------

That is the classic topic of concurrency control.

There are various schemes available for concurrency control; Again a book
would be helpful, but here is an example of concurrency control -

During update, verify the previous values are still the same FOR THE COLUMNS
you are updating in the d/b before the update. A dataset stores all versions
of these values until you do an accept changes.If any of the values have
changed while the client was disconnected - throw an error and rollback the
update (transactional).

Another method could be use the timestamp.

You have to decide upon a concurrency model. And then bridge the gap with
ADO.NET. ADO.NET is flexible enough to support any scheme you might come up
with. Just make sure you donot use Pessimistic concurrency model in a
disconnected system.

Obviously I cannot possibly cover all possibilities in a newsgroup message,
but basically my point is, a dataset includes all various versions of rows
to aid you in concurrency management using standard concurrency control
mechanisms. Ok I won't flog my book on this one, concurrency control is
explained pretty well in David Sceppa's book (MSPress).

- Sahil Malik
You can reach me thru my blog http://www.dotnetjunkies.com/weblog/sahilmalik
 

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