我们数据库的自动增量ID意味着我想维护例如的id号序列。 1,2,3,4,5等。 [英] Auto Increment Id of our database means i want maintain the sequence of id number for eg. 1,2,3,4,5 and so on.

查看:103
本文介绍了我们数据库的自动增量ID意味着我想维护例如的id号序列。 1,2,3,4,5等。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,我在ac#windows应用程序中工作,

i需要帮助,当我在datagridview中显示记录时,我想要那个

并记住在我的SQL中数据库ID是自动增量,当我删除任何行时,
...之后我想维护例如的id号序列。 1,2,3,4,5等...我删除了2个id记录然后将第3个记录移动到2个位置,第4个记录移动到第3个位置,第5个记录移动到4个位置....它可能是否发生如果是的话怎么办????

sir i am working in a c# windows application,
i need help that in when i am showing records in datagridview then i want that
and remember that in my SQL database ID is auto increment,
when i delete any row... after that i want maintain the sequence of id number for eg. 1,2,3,4,5 and so on... i delete the 2 id record then move the third record on 2 position, 4th record move on 3rd position, and 5th record move on 4 position.... it may be happen or not if yes how to do that????

推荐答案

如果你需要这么做,你可以遵循这个......



首先从表中删除自动增量

您必须手动处理
每当你添加记录时,
会增加你自己的CustomID。



当你删除任何记录存储时,另一个表中的ID即DeletedIDTable。

现在当您添加新记录时,首先检查删除的ID是否在DeletedIDTable中可用??

如果有可用的已删除ID,请将该ID分配给新记录并从DeletedIDTable中删除该ID 。

如果不增加CustomId并将其分配给该记录。



If You need this badly you can follow this...

First remove Auto Increment from your table.
You have to handle it Manually .
whenever you add record increase the CustomID by yourSelf.

And when you delete any record store that ID in another Table i.e DeletedIDTable.
Now When You add new record you first check that the deleted Id is available in your DeletedIDTable??
If there is deleted ID available, assign that ID to new record and delete That ID from DeletedIDTable.
If not increase the CustomId and assign it to that record.

//maintain one static CustomId variable for Manually increment.
Static int CustomId = 0;
//When Entering new Record...
List<int> DeletedIDs = new List<int>();

//Get DeletedId list from DeletedIDTable.
DeletedIDs = GetDeletedIds_From_DeletedIdTable().ToList();

if(DletedIDs.count > 0) // if list has DeletedIDs then assign that ID to new Record
{
   //assign DeletedID[0] to new Record.
   //Remove DeletedID[0] from DeletedIDTable.
}
else
{
   //increse your CustomId.
   CustomId++;
   //assign this CustomID to new Record
}





希望这个帮助你

-------------------- -

Pratik Bhuva



Hope This Help You
---------------------
Pratik Bhuva


确实这是一个问题

但删除一条记录后你就无法再对其进行排序

这就是人们在查询中使用ROWNUM概念的原因



ROWNUM不是数据库或表格中的数据。它与数据库中的任何内容都没有关系,包括表,表空间,数据文件或行插入表中的顺序。 ROWNUM是从表中选择的行的编号,将根据选择行的顺序而改变。



示例:

Exactly this is a problem
But after delete a record you can not sort it again
That's why people are using ROWNUM concept in query

ROWNUM is not data in the database or table. It has no relationship to anything in the database, including tables, tablespaces, data files, or to the order in which a row is inserted into a table. A ROWNUM is the number of a row selected from a table and will change depending on the order in which rows are selected.

Example:
SELECT ROWNUM, ID, NAME, SALARY FROM EMP

WHERE ROWNUM < 5







ROWNUM ID NAME SALARY



---------- --------- ------ --------- -



1 100 JOHN 2300



2 110 MILLER 3900

< br $>
3 120 KATE 4500



4 100 TIM 4200




ROWNUM ID NAME SALARY

---------- --------- ------ ----------

1 100 JOHN 2300

2 110 MILLER 3900

3 120 KATE 4500

4 100 TIM 4200


据我所知,没有数据库自动增量字段提供。您不应该使用自动增量并为自己提供这样的功能。
As far as I know, no database auto increment field provides that. You shouldn't use the auto increment and provide yourself such a functionality.


这篇关于我们数据库的自动增量ID意味着我想维护例如的id号序列。 1,2,3,4,5等。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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