重置自动增加DataTable中 [英] Reset AutoIncrement in DataTable
问题描述
我填充的DataSet
与的DataAdapter
到 SQL CE 数据库。数据显示在的DataGrid
这是绑定到数据集的数据表。我有一个自动递增ID字段(或SQLCE,名为 PRIMARY KEY IDENTITY
)的数据源我;相应地,我还设置了自动递增ID列我的数据表
。
I populate a DataSet
with a DataAdapter
to a SQL CE Database. Data is displayed on a DataGrid
which is binded to DataSet's DataTable. I have an auto-increment ID field (or in SQLCE, called PRIMARY KEY IDENTITY
) in my DataSource; correspondingly, I also set a AutoIncrement ID column in my DataTable
.
/* when DataTable is first populated, start counting from Rows.Count */
/* if empty, starts with 1 */
dt.Column["id"].AutoIncrementSeed = dt.Rows.Count + 1;
问题来时,我清楚我的数据表。我想AUTOINCREMENT计数器的值重置为1,但不能,我试过如下:
Problem come when I clear my DataTable. I want to reset the AutoIncrement Counter back to 1 but not able to, I tried the following:
/* clearing and disposing DataTable, DataSet, DataAdaptor does not reset the counter */
dt.Clear();
dt.Dispose();
ds.Clear();
ds.Dispose()
da.Dispose()
/* manually re-setting the AutoIncrementSeed also does not reset the counter */
dt.Column["id"].AutoIncrementSeed = 1;
这只是留下了之前离开柜台清除()
。我怎样才能重置自动增量DataTable中?
It just left with the counter it left off before Clear()
. How can I reset the AutoIncrement in the DataTable?
推荐答案
使用这样
dt.Clear();
dt.Column["id"].AutoIncrementStep = -1;
dt.Column["id"].AutoIncrementSeed = -1;
dt.Column["id"].AutoIncrementStep = 1;
dt.Column["id"].AutoIncrementSeed = 1;
检查下面的链接查看更多
Check the below link for more
http://www.eggheadcafe.com/community/aspnet/10/25407/autoincrementseed.aspx
这篇关于重置自动增加DataTable中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!