473,398 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

DBCurrency

User A and User B modify the same record, UserB save first.
As User A save it , I will get the concurrency error.
I know I can use
Try
..... dsTable.udpate()
catch err As DbCurrency
messagebox.show("UpdateFailed ")
end try

However, How can I let User A know "User B save the same record already ",
and ask USER A whether overwrite it or not , If User A press "Yes" , his
record should saved correctly.
Does anyone know how to do ??
Thanks a lot.
Nov 21 '05 #1
3 1903
Should be possible... here's one way to handle it...

Once you catch the error, show a message box that gives the option whether
or not to replace the existing record (within the catch).

If the user response = Yes, then RELOAD that record into your dataset
(assuming you're using a dataset). If you don't, VB will continue to notice
the data in the dataset still conflicts with what's now in the database.

Next, just overwrite that dataset fields (which now contain User A's data,
which also match what's in the underlying database) with whatever the user B
has entered on-screen. Then just save it (e.g.
OleDbDataAdapter1.Update(DataSet1)).

BTW, even if user answers NO, you may still have to re-load your dataset
with the new data (and refresh the screen with the data saved by user A).
This just helps to avoid other concurrency errors.

Hope this helps!
Tim
"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:O7****************@TK2MSFTNGP12.phx.gbl...
User A and User B modify the same record, UserB save first.
As User A save it , I will get the concurrency error.
I know I can use
Try
.... dsTable.udpate()
catch err As DbCurrency
messagebox.show("UpdateFailed ")
end try

However, How can I let User A know "User B save the same record already ",
and ask USER A whether overwrite it or not , If User A press "Yes" , his
record should saved correctly.
Does anyone know how to do ??
Thanks a lot.

Nov 21 '05 #2
1. there is NO automatic concurrancy checking. the closest visual studio
comes to it is if you use the data adapter wizard to "generate sql
statements" and, under the advanced tab, you select "use optimistic
concurrancy". What this does is simply generate a UPDATE SQL statement that
compares the prior value of all the fields to the current value in the WHERE
clause. If any field has changed the update does not occur (ie: zero records
are updated). This corresponds to the "whole record" method of concurrancy
checking. The other method is to compare last updated timestamp, or some
sort of version number for the record. (ie each time you update a record you
either update the timestamp, or increment the version by 1). The important
thing to realize is that this is basically all a manual method of doing
concurrancy checking. If you don't use the wizard (I never do) then you have
to code some sort of concurrancy check into your update statement manually.

2. there is an exception called "DBConcurrencyException" which, by it's
name, seems to indicate that it will catch concurrency violations... WRONG.
Reading the documentation for it, this exception will be thrown "whenever 0
records are affected" by an sql statement (ie an update statement). Reading
the documentation reveals that "when 0 records are affected it is PROBABLY
due to a concurrency violation" (which YOU have coded in your WHERE clause).

So, the bottom line is this... if you want to catch a concurrency violation
you have to code it yourself using your own methodology. The only tool
ADO.NET gives you is to throw a DBConcurrencyException when 0 records are
affected by an SQL statement. Everything else is up to you to code. Now, I'm
not saying that this is necessarily bad, I'm just saying that it would have
been nice is MS didn't dance around the issue and make it PERFECTLY CLEAR
that there is no automatic concurrency check.

I believe the above statements are correct to the best of my knowledge. I
provide no warrantee, guarantee, or represent that I have any brains at all.

Regards,
John

"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:O7****************@TK2MSFTNGP12.phx.gbl...
User A and User B modify the same record, UserB save first.
As User A save it , I will get the concurrency error.
I know I can use
Try
.... dsTable.udpate()
catch err As DbCurrency
messagebox.show("UpdateFailed ")
end try

However, How can I let User A know "User B save the same record already ",
and ask USER A whether overwrite it or not , If User A press "Yes" , his
record should saved correctly.
Does anyone know how to do ??
Thanks a lot.

Nov 21 '05 #3
Agnes,

Have a look at this sample. Don't see it as a real sample how to use
concurrency.
It shows how the concurrency can be used. The sample is not a real practise
sample.

http://msdn.microsoft.com/library/de...yException.asp

I hope this helps,

Cor
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Pato Secruza | last post by:
How can I print the database structure, including non default variables like Requiered, FieldSize, and most important DESCRIPTION. I want a table like this: ...
9
by: Mike | last post by:
adLongVarChar to 'text' - Mapping ADO types to Native Access types? Okay, so it's not the job of Access to map these types, but has anybody, in the existance of this world ever figured out how to...
9
by: JMCN | last post by:
hi- i have inherited an access 97 database that keeps track of the loans. i have been running into referential intergrity problems when i try to append new loans to table. first of all is a...
4
by: JMCN | last post by:
i have a question regarding the insert into statement in access 97 database. i wrote a small insert statement for my new table def ("tblImportET") but when i run the code, no records are appended...
5
by: deko | last post by:
How to run action query against linked table? I have an Access 2003 mdb with an Excel 2003 Workbook as a linked table. When I attempt to run an action query against the linked table I get this...
7
by: RCS | last post by:
Okay, a rather 'interesting' situation has arisen at a place I work: I need to convert a database from Access to something that can be used over the web. I am currently maintaining and...
3
by: blindsey | last post by:
Is there a tool that can take an Access database and generate SQL "CREATE TABLE" statements for all the tables in it?
2
by: Seth Delaney | last post by:
I have a form with multiple unbound text boxes which serves as a "search form". I can enter my search parameters in the various boxes as needed and click okay. My records are then filtered to...
4
by: Bob | last post by:
Hi all, I'm trying to import data, modify the data then insert it into a new table. The code below works fine for it but it takes a really long time for 15,000 odd records. Is there a way I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.