Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Auto-number Help In Access Db & Vb .net
dhanesh
post Apr 28 2007, 11:50 AM
Post #1


Binary Geek
Group Icon

Group: Members
Posts: 444
Joined: 4-November 05
From: The Digital Arena
Member No.: 9,440



I have a small registration software i made. It basically will just let the person sitting on the software type in details like Name, location, college etc and when the "Enter" is hit, all that info typed on screen goes into an access DB and all the fields get cleared to type in the next record.

Here my Record ID property is set as autonumbered in access. While i run and add records into the software everything works fine say like this :

ID Name Age
1 aaaaa 19
2 bbbbb 21
3 ccccc 20
4 ddddd 18
5 eeeee 22

Now i want to run it in actual live mode and i delete the records 1 - 5 from the access DB, the next time i add a new record through the software, it starts from 6. I also tried deleting 3 & 4 from the list, but instead of rearranging or autorefreshing the numbers it shows like this :

ID Name Age
1 aaaaa 19
2 bbbbb 21
5 eeeee 22

Is there a way i can fix this small glitch ? i.e if i delete any record from between, then the auto number should refresh all the numbers to one after another like this :

ID Name Age
1 aaaaa 19
2 bbbbb 21
3 eeeee 22

Regards
Dhanesh.
Go to the top of the page
 
+Quote Post
faulty.lee
post Apr 28 2007, 02:07 PM
Post #2


Premium Member
Group Icon

Group: [HOSTED]
Posts: 495
Joined: 5-November 06
Member No.: 17,016



QUOTE(dhanesh @ Apr 28 2007, 07:50 PM) *
Now i want to run it in actual live mode and i delete the records 1 - 5 from the access DB, the next time i add a new record through the software, it starts from 6. I also tried deleting 3 & 4 from the list, but instead of rearranging or autorefreshing the numbers it shows like this :

ID Name Age
1 aaaaa 19
2 bbbbb 21
5 eeeee 22

Is there a way i can fix this small glitch ? i.e if i delete any record from between, then the auto number should refresh all the numbers to one after another like this :

ID Name Age
1 aaaaa 19
2 bbbbb 21
3 eeeee 22


That's is actually not a glitch, it's how auto increment works and it's an important feature to ensure data integrity. Say for example, you have another table to keep track of the user's history, maybe last active/visit. It should look like this:
YOUR ORIGINAL TABLE:
ID Name Age
1 aaaaa 19
2 bbbbb 21
3 ccccc 20
4 ddddd 18
5 eeeee 22

HISTORY TABLE:
HistoryID UserID LastVisit
1 1 12/04/2007
2 1 13/04/2007
3 3 15/04/2007
4 2 20/04/2007
5 5 21/04/2007

UserID in history table is referring to your user table. By referring just the ID, you can create a lot of relating table to keep things, and you only need to update 1 table if the user happen to change it's age, since all referring table point to the same ID. That's how relational database works.

Now say you wanted it to works the way it you proposed after deleting a few records:
ID Name Age
1 aaaaa 19
2 bbbbb 21
3 eeeee 22

At this time, in history table, entry 3 which is suppose to refer to "ccccc", is now referring to "eeeee", which is wrong. That's why ID has to remain unique and permanent, representable for each record to ensure that these kind of problem does not happen.

Imagine, say your phone bill account number, which is also auto increment and unique, happen to change when the guy before you decide to disconnect his phone, and the phone company deleted his record.

So, in this case, you are assigning a unique ID to your users, so it has to remain permanent per user. Don't try to fix it, but instead try to exploit it's usefulness.
Go to the top of the page
 
+Quote Post
Quatrux
post Apr 28 2007, 03:28 PM
Post #3


the Q
Group Icon

Group: [HOSTED]
Posts: 1,051
Joined: 13-July 05
From: Lithuania, Vilnius
Member No.: 7,059



I wanted to say the same thing about this issue, even though when I started playing with databases, I also thought that I want the numbers to generate from 1 2 3 and after deletion of 2 to include 2 later, that it would look better.. but with time I understood that it is pointless to look at your auto increment ID and I recommend to keep your eyes away form it and ignore the number, who cares about the number, usually the number, the unique id isn't supposed to be shown, the main thing in the database is the data, but an AutoNumber ID is really good to find and select, update etc. your data, so to conclude, don't care about it, this is the way it needs to work. wink.gif
Go to the top of the page
 
+Quote Post
dhanesh
post Apr 28 2007, 05:54 PM
Post #4


Binary Geek
Group Icon

Group: Members
Posts: 444
Joined: 4-November 05
From: The Digital Arena
Member No.: 9,440



EDIT: In the Access DB the Age field is specified as number and not text. When i try to add the fields from the frontend it acts a little weird. I cant explain how weird cause when a piece of code to add a row is put in, then it shows me a conversion error. Duno how to explain this but if you are familiar with such an error please tell me how to correct it. I use VB >NET 2005.
Thanks

Thanks for getting that off my brains guys tongue.gif , thought it was something from my side. Newayz, the main intension of all this fuss was that the database after getting filled with data would be saved as an excel file for further use. So my concern was not redundancy errors here, tho i understand what this could do in a major application.

Regards
Dhanesh.

This post has been edited by dhanesh: Apr 28 2007, 06:00 PM
Go to the top of the page
 
+Quote Post
faulty.lee
post Apr 28 2007, 06:14 PM
Post #5


Premium Member
Group Icon

Group: [HOSTED]
Posts: 495
Joined: 5-November 06
Member No.: 17,016



If that's what you want, you've 2 option.
1. Create another column named "No", integer. Whenever you update the database, update the column also with incrementing numbering. Or only update the numbering before you export to excel

2. If you're generating the excel from your coding, then manually insert a column whenever you generate the excel file, that column should be the numbering.
Go to the top of the page
 
+Quote Post
Pete
post May 2 2007, 11:09 AM
Post #6


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 1
Joined: 2-May 07
Member No.: 21,752



QUOTE(faulty.lee @ Apr 28 2007, 03:07 PM) *
That's is actually not a glitch, it's how auto increment works and it's an important feature to ensure data integrity. Say for example, you have another table to keep track of the user's history, maybe last active/visit. It should look like this:
YOUR ORIGINAL TABLE:
ID Name Age
1 aaaaa 19
2 bbbbb 21
3 ccccc 20
4 ddddd 18
5 eeeee 22

HISTORY TABLE:
HistoryID UserID LastVisit
1 1 12/04/2007
2 1 13/04/2007
3 3 15/04/2007
4 2 20/04/2007
5 5 21/04/2007

UserID in history table is referring to your user table. By referring just the ID, you can create a lot of relating table to keep things, and you only need to update 1 table if the user happen to change it's age, since all referring table point to the same ID. That's how relational database works.

Now say you wanted it to works the way it you proposed after deleting a few records:
ID Name Age
1 aaaaa 19
2 bbbbb 21
3 eeeee 22

At this time, in history table, entry 3 which is suppose to refer to "ccccc", is now referring to "eeeee", which is wrong. That's why ID has to remain unique and permanent, representable for each record to ensure that these kind of problem does not happen.

Imagine, say your phone bill account number, which is also auto increment and unique, happen to change when the guy before you decide to disconnect his phone, and the phone company deleted his record.

So, in this case, you are assigning a unique ID to your users, so it has to remain permanent per user. Don't try to fix it, but instead try to exploit it's usefulness.


Hi, i have a similar issue but the other way round.
I have an MDB database with a primary key of an auto number and i'm connecting through VB.NET 2005 using drag and drop datasets. In MS Access if i delete a table entry then add another record the autonumber icrements as though the previous record was not deleted (which is good) but in VB.NET when i go to add a new record it will assume the number of that previously deleted within MS Access but i would like it to continue the incrementation in sync with Access as i want to move record from the active table into a completed table but maintain integrity as the auto number is the job number.

Any help would be appreciated.
Go to the top of the page
 
+Quote Post
faulty.lee
post May 2 2007, 12:23 PM
Post #7


Premium Member
Group Icon

Group: [HOSTED]
Posts: 495
Joined: 5-November 06
Member No.: 17,016



QUOTE(Pete @ May 2 2007, 07:09 PM) *
Hi, i have a similar issue but the other way round.
I have an MDB database with a primary key of an auto number and i'm connecting through VB.NET 2005 using drag and drop datasets. In MS Access if i delete a table entry then add another record the autonumber icrements as though the previous record was not deleted (which is good) but in VB.NET when i go to add a new record it will assume the number of that previously deleted within MS Access but i would like it to continue the incrementation in sync with Access as i want to move record from the active table into a completed table but maintain integrity as the auto number is the job number.

Any help would be appreciated.

Don't quite get you. Can you lay out a bit of example to make it clearer?
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Grand Theft Auto: San Andreas(109)
  2. VB: Howto Auto-select Last Item In Listbox(5)
  3. Sharing Files In Windows Xp Home(15)
  4. Decrementing Number Of Digits Ofter Point(15)
  5. Google Suggest (beta)(10)
  6. VB6-MS Access Question(8)
  7. VB.NET / MS Access Question(6)
  8. VB.NET: MS-Access Interaction Tutorial (Part I)(18)
  9. Orkut.com Auto Scrapper - Scrap Ur Friend List In One Go(12)
  10. VB.NET & MS Access Issue(3)
  11. Firefox 2(4)
  12. C++: Basic Classes(5)
  13. Cracking Wireless Access Point Password?(22)
  14. Access(17)
  15. Access 97 To Access 2003(15)
  1. Auto-click Script(7)
  2. Laptop Auto Starts After Turning It Off(8)
  3. Grand Theft Auto Iv(10)
  4. Access Linux Box From Windows Machine- Putty Tool(2)
  5. Integrate Access Database Onto Intranet Site(5)
  6. Domain Name Is Not Assigned To Ip. Access Cpanel With Ip Not With Domain Name.(6)
  7. Auto Volume Controller For Windows(0)
  8. Main Trap17 Site Is Down?(0)
  9. Accessing Ms Access Database From A Centralized Location?(5)
  10. Database Access On Remote Server W/jsp(0)
  11. Access Denied As Admin On Xp, Services Troubles(4)
  12. Ssh Access ?(2)
  13. Cpanel Error When Loggin In...(4)


 



- Lo-Fi Version Time is now: 11th October 2008 - 08:27 PM