cesemj
asked on
How do I create a random number with 3 alaph and 9 digits
Hello,
I have a web form and I am using the FormView data control connected to an AccessDataSource. I am using the web form as a data entry page.
When I click on the Insert button (from the Insert Item Template) to add the new record to the DB table I would like to have an random number like ACN999999999 generated and automatically filled into to the AutoID Field OR is it better to have random number like ICN999999999 generated and automatically filled into to the AutoID Field when the page loads or opens?
To make sure I do not have duplicate AutoID Numbers will the code have to query against tblAutoInventory AutoID field?
I would like to have a random number because the I do not want to use the default AutoNumber and so I can create one to one and one to many relationships with other tables that I will have in the future. If you have a better sugestion please let me know?
NOTE: Instead of using a random number like ICN999999999 I thought of combining the the following to create a unique ID. The Information will come from the form fields that I have to fill in.
Fields
*******
Default Fixed Value: ICN (Inventory Control Number Automaticall filled in)
AutoMFGNumber: 12345 (Ford)
DateRecordCreated: 1014071100PM (Date/Time Field -- System Inserts Time in the field Automatically)
Please HELP me understand how this can be done with VB code.
Thank you in advance,
I have a web form and I am using the FormView data control connected to an AccessDataSource. I am using the web form as a data entry page.
When I click on the Insert button (from the Insert Item Template) to add the new record to the DB table I would like to have an random number like ACN999999999 generated and automatically filled into to the AutoID Field OR is it better to have random number like ICN999999999 generated and automatically filled into to the AutoID Field when the page loads or opens?
To make sure I do not have duplicate AutoID Numbers will the code have to query against tblAutoInventory AutoID field?
I would like to have a random number because the I do not want to use the default AutoNumber and so I can create one to one and one to many relationships with other tables that I will have in the future. If you have a better sugestion please let me know?
NOTE: Instead of using a random number like ICN999999999 I thought of combining the the following to create a unique ID. The Information will come from the form fields that I have to fill in.
Fields
*******
Default Fixed Value: ICN (Inventory Control Number Automaticall filled in)
AutoMFGNumber: 12345 (Ford)
DateRecordCreated: 1014071100PM (Date/Time Field -- System Inserts Time in the field Automatically)
Please HELP me understand how this can be done with VB code.
Thank you in advance,
ASKER
Thank you, Do you have an example and/or article reference that can tell me where to start inorder to build or add the code, for exampke do I add the code to the Protected Sub Button1_click section.
Thank you in advance,
Thank you in advance,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I agree with the above. I suggest generating these numbers at the database as a sequence
ASKER
Hello,
No, the Auto Inventory Record ID will only be used by the user internally. The number will be used to track new parts and parts that have been shipped and/or received, similar to the way Experts Exchange has a unique ID associated with a question that is posted.
I thought about the design approach and agree that it would be best to use date&Time but appending an aditional value which wil equal something like this : ICN101407110023.
Do you have an example and/or reference article that is using this approach,
Thank you again in advance,
No, the Auto Inventory Record ID will only be used by the user internally. The number will be used to track new parts and parts that have been shipped and/or received, similar to the way Experts Exchange has a unique ID associated with a question that is posted.
I thought about the design approach and agree that it would be best to use date&Time but appending an aditional value which wil equal something like this : ICN101407110023.
Do you have an example and/or reference article that is using this approach,
Thank you again in advance,
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you all for guidance,
ASKER
Hello,
I like the concept about the GUID Class. I am reading information articles about the Pros and Cons about using GUIDs.
I like the concept about the GUID Class. I am reading information articles about the Pros and Cons about using GUIDs.
How are your guids going?
ASKER
Thank you for asking, It is going ok,
I created a test table named GUIDTest and created two fields, guidID and name:
guidID: Autonumber set to Replication ID
name: Text
When I create a new record the GUID is created. When I wen into VisualStudio and created a test webform with an accessDataSource bound to the form via the Formview (Insert) and GridView (Edit) controls and used the form view to insert new record, to see if it will work the same as if the GUID field is set to AutoNumber-LongInteger, but for some reason I receive a message when I click on the Insert button saying that guidID cannot be NULL. It almost seems like I have to have the GUID number apear in the guidID field on the Test page when the testpage opens. I am going to recreate the page and try it again. Please let me know if you have any ideas why I might be running into this problem.
I created a test table named GUIDTest and created two fields, guidID and name:
guidID: Autonumber set to Replication ID
name: Text
When I create a new record the GUID is created. When I wen into VisualStudio and created a test webform with an accessDataSource bound to the form via the Formview (Insert) and GridView (Edit) controls and used the form view to insert new record, to see if it will work the same as if the GUID field is set to AutoNumber-LongInteger, but for some reason I receive a message when I click on the Insert button saying that guidID cannot be NULL. It almost seems like I have to have the GUID number apear in the guidID field on the Test page when the testpage opens. I am going to recreate the page and try it again. Please let me know if you have any ideas why I might be running into this problem.
You can generate the random number within a range using
Random a = new Random();
a.Next(26);
where 26 is the max value