问:主键 [英] Q: Primary Key

查看:83
本文介绍了问:主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我对表中主键的值有问题。


我删除了所有的行数据库中的现有数据表使用

代码:


For each x As DataRow in myDataSet.Tables(0)

x.Delete()

下一页


myDataAdaptor.Update(myDataSet.Tables(0))


这很好,但是当我稍后在这个表上添加更多行时,

索引ID不是从1开始,而是看起来它起作用了

先前删除的行集的最后一个值。


我想必须有一些命令我很想重新设置ID计数器。

有人可以提供帮助吗?


提前致谢


Geoff

Hi

I have a problem with the values of a primary key in a table.

I am deleting all the rows of an existing data table in a database by using
code:

For Each x As DataRow In myDataSet.Tables(0)
x.Delete()
Next

myDataAdaptor.Update(myDataSet.Tables(0))

This works fine, HOWEVER, when I add more rows later on to this table, the
index ID does not start from 1, rather it appears that it is working from
the last value of the set of rows deleted earlier.

I guess there must be some command I''m missing to re-set the ID counter.

Can anybody help?

Thanks in advance

Geoff

推荐答案

Geoff,


永远不要在问题上附上问题,原始海报会认为你要给予答案的是b $ b。


数据集是断开连接的,所以它只是开始添加自动密钥来自最新的

,当你没有使用自动增量种子时。


最好是将种子设置为-1和增量。

http://msdn.microsoft.com/library/de...ementtopic.asp


我希望这有帮助吗?


Cor
Geoff,

Never attach a question to a question, the Original Poster would think that
you are giving and answer.

A dataset is a disconnected so it just start adding autokeys from the latest
it had when you not are using the autoincrement seed.

The best is to set the seed to -1 and the increment as well.

http://msdn.microsoft.com/library/de...ementtopic.asp

I hope this helps?

Cor


Apologies Cor在上面发布。只有在发送后我才意识到

第一响应者没有留在同一个帖子中。


我会查看你的链接。


谢谢


Geoff


" Cor Ligthert" <无********** @ planet.nl>在消息中写道

news:eq **************** @ TK2MSFTNGP10.phx.gbl ...
Apologies Cor for posting in the above. Only after sending did I realise
that the first responder had not stayed in the same thread.

I''ll have a look at your link.

Thanks

Geoff

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eq****************@TK2MSFTNGP10.phx.gbl...
Geoff,

永远不要在问题上附上问题,原始海报会认为你提供和回答的是


数据集是断开连接的,所以它只是开始添加自动键当你没有使用自动增量种子的时候最新的


最好的是将种子设置为-1和增量。

http ://msdn.microsoft.com/library/de...ementtopic.asp
我希望这有帮助吗?

Cor
Geoff,

Never attach a question to a question, the Original Poster would think that you are giving and answer.

A dataset is a disconnected so it just start adding autokeys from the latest it had when you not are using the autoincrement seed.

The best is to set the seed to -1 and the increment as well.

http://msdn.microsoft.com/library/de...ementtopic.asp
I hope this helps?

Cor



Hi Cor


呃,我怕我不跟着你:


数据集是断开连接的,所以它只是从

最新的

开始添加自动键。你没有使用自动增量种子。


最好将种子设置为-1和增量。


我知道数据集已断开连接。我正在删除数据库中的所有记录

,删除数据集中的记录,然后使用

Update将更改传输到数据库本身。我也是,感兴趣的是
,之后使用

RemoveAt删除DataSet中的所有记录。


但是,正如我在第一篇文章中所说,当我向DataSet添加一条记录时,

(在DataGrid中的ID为1 - 这是我的期望)然后

更新到数据库,ID不是1!相反,它比最初删除的

记录数多一个。所以,恕我直言,数据库ID不知道
知道早先的记录已被删除。


这有意义吗?

Geoff
Hi Cor

Err, I''m afraid I don''t follow you:

"A dataset is a disconnected so it just starts adding autokeys from the
latest
it had when you not are using the autoincrement seed.

The best is to set the seed to -1 and the increment as well."

I understand that a dataset is disconnected. I''m deleting all the records in
the database itself by deleting the records in the dataset and then using
Update to transfer the changes to the database itself. I''m also, as a matter
of interest, deleting all the records in the DataSet afterwards using
RemoveAt.

However, as I said in the first post, when I add a record to the DataSet
(which in a DataGrid has the ID of 1 - which is what I expect) and then
Update it to the database, the ID is not 1! Instead, it is one more than the
number of records deleted initially. So, IMHO, the databases ID does not
know that the earlier records have been deleted.

Does this make sense?

Geoff


这篇关于问:主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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