Generating unique IDs using VB
Generating unique IDs using VB
Generating unique IDs using VB
Generating unique IDs using VB
Generating unique IDs using VB
Generating unique IDs using VB Generating unique IDs using VB Generating unique IDs using VB Generating unique IDs using VB Generating unique IDs using VB Generating unique IDs using VB Generating unique IDs using VB Generating unique IDs using VB
Generating unique IDs using VB Generating unique IDs using VB
Generating unique IDs using VB
Go Back  Xtreme Visual Basic Talk > > > Generating unique IDs using VB


Reply
 
Thread Tools Display Modes
  #1  
Old 03-21-2011, 03:08 AM
Ritwika Ritwika is offline
Newcomer
 
Join Date: Mar 2011
Posts: 2
Default Generating unique IDs using VB


How can i generate id numbers using visual basic?

I have a TOAD table HealthSystemArticles with an attribute id_no

Everytime i upload a value to the table, i want to generate an id_no which is equal to the max(id_no) in the table + 1 and then upload it back to the table.

How can i do this?

Thank you
Regards,
Ritwika
Reply With Quote
  #2  
Old 03-21-2011, 06:01 PM
jantje jantje is offline
Junior Contributor
 
Join Date: Dec 2004
Posts: 255
Default

a Toad table? Don't you mean Oracle? Toad is a client for Oracle databases.
Anyway, if Oracle, try not to use max(id) ever
Max(id) is always bad. (not only in Oracle but every RDBMS)
You should use a sequence and a trigger
eg
Code:
CREATE SEQUENCE somefield_seq
    MINVALUE 1
    MAXVALUE 999999999999999999999999999
    START WITH 1
    INCREMENT BY 1;
The sequence is something like a variable and increments everytime it is called.
You can create a trigger also to create a autonumber field
eg
Code:
CREATE OR REPLACE TRIGGER
somefield_autoid_trg BEFORE INSERT ON yourtable
FOR EACH ROW
WHEN (new.yourid IS NULL)
BEGIN
  SELECT somefield_seq.NEXTVAL
  INTO   :new.yourid
  FROM   dual;
END;
Now you can insert new rows and the id field (or whatever field you wish) is an autonumber.
Reply With Quote
  #3  
Old 06-01-2011, 12:24 PM
alexsts alexsts is offline
Freshman
 
Join Date: Apr 2010
Posts: 32
Wink autonumber is your answer

Quote:
Originally Posted by Ritwika View Post
i want to generate an id_no which is equal to the max(id_no) in the table + 1 and then upload it back to the table.


Ritwika


Open that table in design view and make sure that field in question set to auto-number. That will take care of that small issue.
Problem could be that you already have some data in the table then you will need to create trigger as suggested earlier. Or you can introduce new field and set it to auto-number.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Generating unique IDs using VB
Generating unique IDs using VB
Generating unique IDs using VB Generating unique IDs using VB
Generating unique IDs using VB
Generating unique IDs using VB
Generating unique IDs using VB Generating unique IDs using VB Generating unique IDs using VB Generating unique IDs using VB Generating unique IDs using VB Generating unique IDs using VB Generating unique IDs using VB
Generating unique IDs using VB
Generating unique IDs using VB
 
Generating unique IDs using VB
Generating unique IDs using VB
 
-->