如何在MS Access中不设置为自动编号的情况下增加主键值(ID) [英] how to increase the primary key value (ID) without set as Auto number in MS access

查看:74
本文介绍了如何在MS Access中不设置为自动编号的情况下增加主键值(ID)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI
我创建了用于获取Stop-ID最大值的视图,因此在StopNew()函数中,我将向该Max Stop-ID加1.

HI
i created view for getting the maximum value of Stop-ID,So in StopNew() function i will add 1 to that Max Stop-ID

public void StopNew()
       {

           this.MaxStopIDbindingSource.EndEdit();

           stopBindingSource.AddNew();
           this.MaxStopIDbindingSource.MoveFirst();
           ((DataRowView)this.stopBindingSource.Current).Row["nStopID"] = (int)((DataRowView)this.MaxStopIDbindingSource.Current).Row["nID"] + 1;

       }


但是最大ID不会在运行时更新.这意味着视图值不会在运行时更新.


but the max ID will not update in runtime, means view value will not updated in runtime.

推荐答案

我在这里猜测很多,但这是视图的原因不会在运行时更新是因为您尚未更新数据库-确定提交新记录后,视图将立即更新吗?

如果需要能够添加多个记录,则在提交更改之前,必须在内部跟踪ID直到更新.

当然,这假设这是一个单用户数据库.

对于多用户数据库,如果您需要在不先将行ID更新到数据库的情况下知道行的ID,则必须实现一个新表,其中包含下一个可用(或上次使用)ID -并在您每次向集合中插入记录时更新该表-这样,每个用户都可以获取下一个可用的ID.
I''m guessing a lot here, but the reason your view won''t update at runtime is because you haven''t updated your database yet - surely as soon as you commit the new record, your view will update?

If you need to be able to add multiple records, before committing your changes, then you''d have to keep a track of the id internally until you update.

This assumes this is a single-user database, of course.

For a multi-user database, if you need to know the value of a row;s ID without updating it first to the database, then you''d have to implement a new table, holding the next available (or last used) Id - and update that table every time you insert a record to your collection - that way every user gets the next available Id regardless.


这篇关于如何在MS Access中不设置为自动编号的情况下增加主键值(ID)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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