【发布时间】:2010-10-16 22:30:46
【问题描述】:
我在数据表中插入了一些行
设置 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),它并没有改变 任何想法都值得赞赏
【问题讨论】:
标签: sql-server-2005 .net-3.5 sql-server-ce