【发布时间】:2011-05-12 02:26:20
【问题描述】:
我用DataAdapter 将DataSet 填充到SQL CE 数据库。数据显示在绑定到 DataSet 的 DataTable 的 DataGrid 上。我的数据源中有一个自动增量 ID 字段(或在 SQLCE 中,称为 PRIMARY KEY IDENTITY);相应地,我还在我的DataTable 中设置了一个 AutoIncrement ID 列。
/* when DataTable is first populated, start counting from Rows.Count */
/* if empty, starts with 1 */
dt.Column["id"].AutoIncrementSeed = dt.Rows.Count + 1;
当我清除我的 DataTable 时出现问题。我想将 AutoIncrement Counter 重置回 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() 之前离开的计数器。如何重置 DataTable 中的 AutoIncrement?
【问题讨论】: