hi everyone

im doing small vbproject that must auto generate id using the current date format in vb.net-(VISUAL STUDIO 2012) with Ms access database. When the button1 click the autonumber should be displayed in text. And when it save, it should be saved in the database access. The id number should be like this eg: "1125130000, 11251300001" and so on.

please someone kindly help me as soon as possible. please.
Thanks in advance.

Member Avatar for Rahul47

You should do the following on button click

Get the maximum number from database, increment it and then store it.

thanks for reply

i want automatic generating id be done in the database with the current date, and anytime when the the button is click on vb form the new generated id should be displayed in the text.

thanks

Member Avatar for Rahul47

Well you can extract the date,month and year using Date functions and then apply following algorithm.

1) Extract month (suppose you got 11) then,
    id=month     (id=11)

2) Extract date (suppose you got 9 ) then,
    id=id*100 + date   (id=1100 + 9=1109)

3) Extract year (suppose you got 13) then,
    id=id*100 + year   (id=110900 + 13=110913)

4) Then as i see you wish to have 5 digits space so do
        id=id*100000  (id=11091300000)

5) Now you can increment the user on button click.

Is a hard 5 digit sequence required? If all you need is something that's larger than the previous ID and smaller than the next, you can use the custom date time formatting to get a high enough resolution that practically guarantees uniqueness:

' Timestamp down to the millisecond
Id = DateTime.Now.ToString("yyMMddHHmmssFFF")
commented: Can be shorthanded by calling Now() +9

hi Rahul47
sory for late reply,,thanks to you man, i got the logic.

hi deceptikon

thanks for the response. Maybe i'll try that one.

Well computer DateTime is actually stored at a 64bit number.

This number started on Jan 1, 1970.

so for you ID you can use this 64bit number as it can uniquely identify a record. It can also be used (with some additional processing) to give you a DateTime. 2 Birds with one stone

:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.