I need a number that can never be duplicated.

A

Armin Zingler

Cor said:
Or do you get every 100-nanosecond a new customer?

:)

Only an addition: The unit is 100-nanoseconds but the resolution might be
1/100s only.

...which should be still enough customers. :)
 
G

Guest

If you want to go this route, here's how I have SQL Server generate a RowID for me..

1. Use a Stored Procedure to add the new row

2. Use a parameter in the sproc to return the identit
DECLARE @NewRowID int OUTPU

3. Immediately after the INSERT and error check (if applicable), set @NewRowID to the identit
SET @NewRowID = Scope_Identity(

4. In your vb code, set the direction of the parameter to Output..
prmNewRowID.Direction = ParameterDirection.Outpu

5. After executing the sproc, retrieve the value from SQLCommand.Parameter
RowIDVariable = CInt(SQLCommand.Parameters("@NewRowID").Value

I think this is the best way to let SQL Server sort out unique numbers for records. It's very common in multi-user applications for the user to execute a transaction and then receive a unique number back from the database in this fashion

I hope this helps, it seems it would be nicer to have Customer #12345 rather than Customer #{D579116A-EE83-4fb0-BB87-72AF7E509088}. :-

Best Regards
Mark Lauser - Crimson Softwar
 

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