计数并用1再次启动

问题描述 投票:0回答:1

即时通讯思想很长一段时间的解决方案,但我不找到任何解决我的问题:

说明:我有变量x。 x是在我的Oracle数据库1和99之间的ID号。

之后,我填写我插入,直到Max在我的分贝8行(因为我有动态文本框,所以我从1行至插入8个丝束)的形式。现在我想计数x直到99并达到99后,应在1再次启动。

问题是,我竟然插入以下行:

Row1: Insert (text, 97) (97 is the ID)
Row2: Insert (text, 98) (98 is the ID)
Row3: Insert (text, 99) (99 is the ID)
Row4: Insert (text, 100) (100 is the ID) now here is the problem, it should begin at 1 again and insert 1.
Row5: Insert (text, 101) (101 is the ID) should be 2.
...

我希望有人知道容易的解决方案。

非常感谢你

c# if-statement while-loop insert id
1个回答
2
投票

要采取一个除法的余数,你可以使用模运算%。但是,效果最好的是0开始所以,如果你减去1的'x'从映射到1-99 0-98,您可以拿模量,并采取一个除法的余数由99然后,你可以映射序列回1-99再次加入1。所以语句变成

int id = (x - 1) % 99 + 1; 

编辑:不太清楚你在你的问题是什么意思。但如果你的102 x的值,那么标识符成为3.确实是先减1,所以它的101。然后它采用时99这2分频其余部分,然后再加1,所以变得3.使对应于102的x id的值是3。

© www.soinside.com 2019 - 2024. All rights reserved.