0

我已经在数据表中插入了一些行

设置 Identity_insert tblEvent on

然后我尝试“重新播种”身份字段

int MaxId = this.MaxID()+1;
string upgrade = "ALTER TABLE " + Table + " ALTER COLUMN ID IDENTITY("+ MaxId.ToString() +",1)";
System.Data.SqlServerCe.SqlCeCommand cmd = new System.Data.SqlServerCe.SqlCeCommand(upgrade, connection);
cmd.CommandType = System.Data.CommandType.Text;
connection.Open();
cmd.ExecuteNonQuery();
connection.Close();

“MaxId”由下式确定

int MaxId = 0;
string upgrade = "select Max(ID) from " + Table;
System.Data.SqlServerCe.SqlCeCommand cmd = new System.Data.SqlServerCe.SqlCeCommand(upgrade, connection);
cmd.CommandType = System.Data.CommandType.Text;
connection.Open();
MaxId = (int)cmd.ExecuteScalar();
connection.Close();
return MaxId;

但是,如果我在播种后再次查询 Max(ID),它并没有改变任何想法的价值

4

2 回答 2

0

奇怪,可能是权限问题。不过,您应该已经看到了异常,除非异常被全部捕获。

于 2009-04-02T18:54:28.453 回答
0

尝试这个:

string upgrade = " DBCC CHECKIDENT('[" + Table + "]', RESEED, " + (MaxId + 1)+ " )"
于 2009-04-01T17:47:30.407 回答