Sql server 2005 SQL Server 2005 CE 3.5重新设定种子标识
我已经在数据表中插入了一些行 设置标识\u插入tblEvent on 然后,我尝试“重新设置”标识字段的种子Sql server 2005 SQL Server 2005 CE 3.5重新设定种子标识,sql-server-2005,.net-3.5,sql-server-ce,Sql Server 2005,.net 3.5,Sql Server Ce,我已经在数据表中插入了一些行 设置标识\u插入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
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;
但是,如果我在设定种子后再次查询MaxID,它并没有改变
任何想法都是正确的试试这个:
string upgrade = " DBCC CHECKIDENT('[" + Table + "]', RESEED, " + (MaxId + 1)+ " )"
奇怪,可能是权限问题。不过,您应该已经看到了一个异常,除非该异常被一个“包罗万象”所吞噬。谢谢,我还以为CE3.5不支持DBCC呢?