473,320 Members | 1,722 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,320 software developers and data experts.

Multi-user environment, prevent PK violation

In a multi-user environment, how would I prevent users from adding Orders
with identical OrderID. For instance I have following tables in my database

Order
==================
OrderID Identity field
CustomerID
OrderDate
DeliveryAddress

OrderDetail
==================
OrderID
ProductID
UnitPrice
Quantity

Now, User A and User B view all the order placed by a customer. OrderID in
the DataSet would have AutoIncrement to True. When User A and User B add a
new order they both will have identical OrderID in the DataSet and add method
will fail for one of the user because of Primary Key violation constraint.

How can I prevent this from happening, so that it assigns a different
OrderID without generating an error?

Jul 21 '05 #1
1 1723
One quick way it to assign the column in the database as an identity column
and let the DB engine auto-increment that number there.

Depending on what you want to do and how you want the number formatted this
may or may not work for you. One thing I have done in the past was use a
composite value as the PK in an order table. Each order entry person had a
specific numeric prefix assigned to them and then the DB was in charge of
incrementing a field to provide a unique number for each order entered. Once
the order was saved the real order number referenced throughout the rest of
the system was a composite of the order entry persons unique prefix and then
the sequential number that the DB assigned to that particular entry.

....but you mileage may vary..

There is always a way to do something, sometimes you just need to fiddle
around and find the way that is best for your case.

You might also decide to keep a table of available order numbers populated
ahead of time and just have a system that takes a request and assigns one of
them to each request.
"Job Lot" <Jo****@discussions.microsoft.com> wrote in message
news:42**********************************@microsof t.com...
In a multi-user environment, how would I prevent users from adding Orders
with identical OrderID. For instance I have following tables in my
database

Order
==================
OrderID Identity field
CustomerID
OrderDate
DeliveryAddress

OrderDetail
==================
OrderID
ProductID
UnitPrice
Quantity

Now, User A and User B view all the order placed by a customer. OrderID in
the DataSet would have AutoIncrement to True. When User A and User B add a
new order they both will have identical OrderID in the DataSet and add
method
will fail for one of the user because of Primary Key violation constraint.

How can I prevent this from happening, so that it assigns a different
OrderID without generating an error?

Jul 21 '05 #2

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

Similar topics

4
by: Frank Jona | last post by:
Intellisense with C# and a multi-file assembly is not working. With VB.NET it is working. Is there a fix availible? We're using VisualStudio 2003 Regards Frank
12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
0
by: frankenberry | last post by:
I have multi-page tiff files. I need to extract individual frames from the multi-page tiffs and save them as single-page tiffs. 95% of the time I receive multi-page tiffs containing 1 or more black...
6
by: cody | last post by:
What are multi file assemblies good for? What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a single multi file assembly (A.DLL+A.NETMODULE)?
6
by: Joe | last post by:
I have 2 multi-list boxes, 1 displays course categories based on a table called CATEGORIES. This table has 2 fields CATEGORY_ID, CATEGORY_NAME The other multi-list box displays courses based on...
4
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the...
5
by: Shane Story | last post by:
I can seem to get the dimensions of a frame in a multiframe tiff. After selecting activeframe, the Width/Height is still really much larger than the page's actual dimensions. When I split a...
5
by: dkelly925 | last post by:
Is there a way to add an If Statement to the following code so if data in a field equals "x" it will launch one report and if it equals "y" it would open another report. Anyone know how to modify...
0
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing...
1
by: mknoll217 | last post by:
I am recieving this error from my code: The multi-part identifier "PAR.UniqueID" could not be bound. The multi-part identifier "Salary.UniqueID" could not be bound. The multi-part identifier...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.