的MySQL AutoInc的C#数据列AutoInc. [英] Mysql AutoInc & C# data column AutoInc.

查看:54
本文介绍了的MySQL AutoInc的C#数据列AutoInc.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生

现在我有一个问题,进行了很多搜索,没有找到任何可行的解决方案,

现在我有带有ID列的表,该列具有主键和自动增量
现在,如果当前ID为5,并且我输入一行,然后将其删除,那么下一个新ID应该为7,而不是6 OK,但是在使用databinding.addnew()之后的VS 2005 C#中,C#获得了最后一个ID,即5和inc .它由1变为6,而不是7,所以Mysql Autoinc和C#autoinc

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

推荐答案

否之间的同步如何.它不是那样工作的.当您生成新的自动编号时,将为其分配下一个编号-它将永远不会重复使用旧编号.原因有两个:

1)在您描述的情况下,创建ID为3、4和5的记录.然后删除4.如果下一条记录的ID为4,那么您给下一个记录取什么值?从逻辑上讲,应该再次为5!

2)它不知道您没有使用ID来引用其他表中的记录:如果将ID重新分配给先前使用的值,那么所有其他表记录现在都将引用给不同的用户!
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!


这篇关于的MySQL AutoInc的C#数据列AutoInc.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆