I had the same problem and
transactions solved my problem. There are transaction commands in TSQL and ADO or ADO.NET.
In all of them, you have to do something like this :
start transaction
get biggest id
compute next id
insert new record with new ID
commit transaction
And another point is that transactions have multiple isolation levels and the clearest one for this type of problems is
Serializable
one.
For more information please read :
http://msdn.microsoft.com/en-us/library/ms188929.aspx[
^]
http://msdn.microsoft.com/en-us/library/ms173763.aspx[
^]
http://msdn.microsoft.com/en-us/library/2k2hy99x%28v=vs.71%29.aspx[
^]
If you say that in which of TSQL , ADO or ADO.NET you are interested, I'll provide the code for you. However I'm sure that you have got the point.