views:

402

answers:

2

I have inserted some rows into a data table with

Set Identity_insert tblEvent on

I then attempt to 'reseed' the Identity field

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' is determined by

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;

However, if I query Max(ID) again after seeding it has'nt changed Any idea's aprreciated

A: 

Try this:

string upgrade = " DBCC CHECKIDENT('[" + Table + "]', RESEED, " + (MaxId + 1)+ " )"
Thanks,I thought DBCC was not supported on CE 3.5 though?
A: 

weird, could it be a permissions issue. you should have seen an exception though, unless the exception is gobbled up by a catch all.

Gnana