Generate a transaction id - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Generate a transaction id

azdonaldazdonald Posts: 31Member
Hi please i would like to generate a transaction id for my application something like TR1234 and i want it to be serially. The application is a server/client application. How do i go about it???

Comments

  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    Serially? As in you would like the number to be a series?

    Not sure exactly what you are looking for, but from my experience, Transaction IDs have some form of "smart number" capabilities, and usually involve a structure.

    For instance, a number like 063-554-4958582 could mean: 063 is a store location, 554 is the money type for the transaction, 4958582 is the transaction # for this year (the first transaction being xxx-xxx-0000001)

    In this case, I would first identify all information I want to get from my conf-number, I would then create a smart number system for each part of the transaction ID, (00A = Monday, 4R = UTAH, 001 = JANUARY) these sorts of things...

    Next I would identify a place to keep a running total of the transactions and store additional information about them (whatever I needed for my scenario).

    Each section of the transaction ID should be a separate field in the TRANSACTION_ID table, and they should be all combined into one line in the TransID Field of any table refering to that information

    Hope this helps,
    Sean
  • azdonaldazdonald Posts: 31Member
    Well i thought of selecting the last inserted transaction id and probably add one to it when the form loads but its a client/server app running on several machines so i figured it wont be a bad idea cos it will over work the server creating unnecessary connections and so on.
    Your idea seems ok but i dont really have a criteria for the transid. i just want a bunch of unique numbers.
  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    If you are looking for a unique identifier, a field that can declare a record in a database unique, you can try using a GUID.

    Globally Unique ID - GUID

    GUIDs are 36 characters long (32 numbers 4 dashes I think), and can be stored in nvarchar fields or in Unique Identifier fields in the database. If you are using SQL Server you can create a field, and set it to UniqueIdentifier, then in the properties set "isRowGuid" to True and it will automatically generate a GUID for that row when a record is added.

    You can generate GUIDs with Vb.Net as well:
    [code]
    Dim MyGuid As String = Guid.NewGuid.ToString()
    'OR
    Dim MySecondGuid As Guid = Guid.NewGuid()
    [/code]

    hope this helps,
    Sean C
Sign In or Register to comment.