Question

I'm attempting to generate a unique number (which will be used as an identity number to a row in a DataTable) For a stock order application, where I enter a stock item number, select a supplier, and click "order" and it generates the number, and enters it into a new data row under a column called "Order Number". I understand that GUID can do what I need, but it generates a number thats too long, and are random. I require sequential numbers (e.g : 1,2,3,4).

Était-ce utile?

La solution

If a database is being used to store orders, use an order-ID identity column - for example:

CREATE TABLE dbo.Orders
(
    OrderID into IDENTITY(1,1),
    -- other columns
)

If not (which seems unlikely), use a singleton or static order-number generator that returns the max order number returned previously plus one.

You could implement this max-plus-one logic in the button-click event handler too of course, but I would just plan on order-number generation as a responsibility to encapsulate in a distinct type.

Autres conseils

If you want a sequential number, you don't need a GUID, you should do that in your database.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top