我填充一个DataSet
with a DataAdapter
to a SQL CE数据库。数据显示在DataGrid
它绑定到 DataSet 的 DataTable。我有一个自动递增 ID 字段(或在 SQLCE 中,称为PRIMARY KEY IDENTITY
)在我的数据源中;相应地,我还在我的中设置了一个自动增量ID列DataTable
.
/* when DataTable is first populated, start counting from Rows.Count */
/* if empty, starts with 1 */
dt.Column["id"].AutoIncrementSeed = dt.Rows.Count + 1;
当我清除数据表时出现问题。我想将自动增量计数器重置回 1 但无法,我尝试了以下操作:
/* 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;
它刚刚离开了之前留下的柜台Clear()
。如何重置数据表中的自动增量?
像这样使用
dt.Clear();
dt.Column["id"].AutoIncrementStep = -1;
dt.Column["id"].AutoIncrementSeed = -1;
dt.Column["id"].AutoIncrementStep = 1;
dt.Column["id"].AutoIncrementSeed = 1;
检查以下链接了解更多信息
http://www.eggheadcafe.com/community/aspnet/10/25407/autoincrementseed.aspx
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)