DataSet

Auto incrementing is found in many database products, but how can it possibly work

properly in your application? The connected classes haven’t been covered yet, but you can

imagine that at some point you might want to send your new data to a back-end database. If

your application supplies the auto-increment values, what will the database do, especially if it

receives duplicate values from different client applications?

The answer is that these auto-increment values are never sent to the database because the

auto-increment column in the database table will provide a value when the new row is added.

After each new row is added, the back-end database table generates a new auto-increment

number, and then your application will query the database to get the newly created number.

Your application will then update its primary key number to the values that came from the

database. This means that all foreign key references will need to be updated as well.

So what happens if you add new rows in your application to generate auto-increment

values of 1 to 100 and then send these rows back to the database table, and the table already

has 10 rows? When the first row is sent from your application, it has an auto-increment value

of 1. The new auto-increment number created in the database will be 11. Your application

queries for the 11 and tries to change the 1 to an 11 but throws an exception because 11 is

already in your data table.

To solve this problem, set

AutoIncrementSeed to -1 and set AutoIncrementStep

to -1. This

will cause negative numbers to be generated; they won’t conflict with the values coming from

 

the database because the database doesn’t generate negative numbers.

 

 

转载于:https://www.cnblogs.com/joe-yang/archive/2012/05/04/2482595.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值