-
Re: Update method in ADO.NET - more...
Hi again!
It's fun talking to myself ;-)
Anyway, digging deeper into the Update-method, I'm trying to figure out how
to code for concurrency issues. Say I update 3 records in my DataTable, while,
at the same time, someone updates record no 2 in the underlying database.
(I've simulated this by opening the table in question from Server Explorer,
while pausing my VB.NET app with a msgbox)
This is what seems to happen: The first record is being updated, the second
record generates a Concurrency Exception, which is OK. But the third record
is *not* updated. It seems that the first record to hit an exception halts
the entire process, so any records after the bad one aren't propagated back
to the db!
I have a gut feeling that I'm missing something here. The only way of coding
this logic I can see would be along the lines of calling Update in a loop,
resolving the first bad record somehow, and terminating the loop when no
more errors occured. Would possibly work, but seems cumbersome.
Any ides?
/TIA
-
Re: Update method in ADO.NET - more...
Set the DataSet ContinueUpdateOnError property to True before calling
Update. That causes the dataset to update
all rows where no errors occur, and sets the RowError property of the rows
that caused errors. You can retrieve the error by write code for the
RowUpdated event, which fires every time the dataset updates the row. The
RowUpdated event receives a SqlRowUpdatedEventArgs object that exposes an
Errors property
"martin rydman" <martin@aprire.se> wrote in message
news:3bb749de$1@news.devx.com...
>
> Hi again!
> It's fun talking to myself ;-)
>
> Anyway, digging deeper into the Update-method, I'm trying to figure out
how
> to code for concurrency issues. Say I update 3 records in my DataTable,
while,
> at the same time, someone updates record no 2 in the underlying database.
> (I've simulated this by opening the table in question from Server
Explorer,
> while pausing my VB.NET app with a msgbox)
>
> This is what seems to happen: The first record is being updated, the
second
> record generates a Concurrency Exception, which is OK. But the third
record
> is *not* updated. It seems that the first record to hit an exception halts
> the entire process, so any records after the bad one aren't propagated
back
> to the db!
>
> I have a gut feeling that I'm missing something here. The only way of
coding
> this logic I can see would be along the lines of calling Update in a loop,
> resolving the first bad record somehow, and terminating the loop when no
> more errors occured. Would possibly work, but seems cumbersome.
>
> Any ides?
>
> /TIA
-
Re: Update method in ADO.NET - more...
Hi Russell!
Always trust your gut feeling :-) I'll check it out right now!
/Martin
-
Re: Update method in ADO.NET - more...
Hi again, Russell!
Well, I tried to find the ContinueUpdateOnError property, but I can't, neither
in help nor in object browser. We are talking about ADO.NET, VS Beta 2, right?
Sorry, but it ain't there, or I'm goofing big time 
Any hints?
TIA
/Martin
-
Re: Update method in ADO.NET - more...
In earlier builds, trap update errors and check the RowError property of the
DataRow object. You can continue the update by setting the UpdateStatus to
Continue in the RowUpdated event.
"martin rydman" <martin@aprire.se> wrote in message
news:3bb87110$1@news.devx.com...
>
> Hi again, Russell!
>
> Well, I tried to find the ContinueUpdateOnError property, but I can't,
neither
> in help nor in object browser. We are talking about ADO.NET, VS Beta 2,
right?
> Sorry, but it ain't there, or I'm goofing big time 
>
> Any hints?
>
> TIA
>
> /Martin
-
Re: Update method in ADO.NET - more...
Hi Russell!
Thanks for taking your time...
OK, I managed to get all rows updated except for the one altered by another
process by this code:
Private Sub myDataAdapter_RowUpdated(...)
e.Status = UpdateStatus.Continue
End Sub
I'm now trying to figure out how to quickly filter out rows that didn't get
updated. I tried varios objects' HasErrors-property, but the above seems
to somehaow eliminate errors altogether. I could loop through my table and
compare Current and Original Values, but that seems kinda' stupid. I also
tried to create a DataView and filter it, but failed
If you'd care to stay with me on this one, do you have any further suggestions?
BTW, your previous response suggests that there are later builds of Beta
2 than the one I got (MSDN, version 7.0.9254 of VS). Are there?
TIA!
/Martin
-
Re: Update method in ADO.NET - more...
You'll need to build a collection of rows that didn't update properly.
Again, check the RowErrors property of the DataRow object to determine the
error. As the RowUpdated event fires for every row, you can use the
RowErrors property to add only those rows that have errors to your
collection.
"martin rydman" <martin@aprire.se> wrote in message
news:3bb88f1c$1@news.devx.com...
>
> Hi Russell!
>
> Thanks for taking your time...
> OK, I managed to get all rows updated except for the one altered by
another
> process by this code:
>
> Private Sub myDataAdapter_RowUpdated(...)
> e.Status = UpdateStatus.Continue
> End Sub
>
> I'm now trying to figure out how to quickly filter out rows that didn't
get
> updated. I tried varios objects' HasErrors-property, but the above seems
> to somehaow eliminate errors altogether. I could loop through my table and
> compare Current and Original Values, but that seems kinda' stupid. I also
> tried to create a DataView and filter it, but failed
>
> If you'd care to stay with me on this one, do you have any further
suggestions?
>
> BTW, your previous response suggests that there are later builds of Beta
> 2 than the one I got (MSDN, version 7.0.9254 of VS). Are there?
>
> TIA!
>
> /Martin
>
-
Re: Update method in ADO.NET - more...
Hi Russell!
>You'll need to build a collection of rows that didn't update properly.
>Again, check the RowErrors property of the DataRow object to determine the
>error. As the RowUpdated event fires for every row, you can use the
>RowErrors property to add only those rows that have errors to your
>collection.
I finally came up with this after your info:
Private Sub myDataAdapter_RowUpdated(...)
If Not e.Errors Is Nothing Then
MsgBox(e.Row.HasErrors)
End If
e.Status = UpdateStatus.Continue
End Sub
Curiously enough, even though e.Errors (correctly) is defined for bad rows,
e.Row.HasErrors returns False. Seems the row itself is not in error, but
the RowUpdated event receives error-info through the event-arg.
Anyway, many thansk for your input!
/Martin
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks