Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dear sir

now i have a problem and searched a lot and did not find any working solution ,

now i have table with ID column which Primary Key & Auto Increment
now if the current ID is 5 and i enter a row then i deleted it , so the next new ID should be 7 not 6 OK but the VS 2005 C# after using databinding.addnew() the c# get the last ID which 5 and inc. it by one so it will be 6 not 7 so how the sync between Mysql Autoinc & C# autoinc
Posted

1 solution

No. It doesn't work like that. When you generate a new autonumber, it is assigned the next number - it will never re-use old numbers. There are two reasons:

1) In the situation you describe, you create records with ID 3, 4, and 5. You then delete 4. If the next record is given an ID of 4, what value do you give the following one? Logically, it should be 5, again!

2) It doesn't know that you haven't used the ID to refer to that record in a different table: if it re-allocates the ID to a previously used value, then all those other-table records will now refer to a diffent user!
 
Share this answer
 
Comments
AhmedOsamaMoh 18-May-11 2:46am    
mysql autoinc. is normal and but the problem now in C# , the next new ID must be same in c# and mysql , i use also such ID in a linked table so the reuslt for example ID in Mysql is 6 but the ID generated in the c# is 5 and it stored in the linked table as 5 although in real it is 6 and no record with ID 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900