i have a datatable Dtable with 3 columns in my winforms. in which 1 column is identity column. the columns are
DataTable Dtable = new DataTable();
DataColumn Dcolumn1 = new DataColumn("Slno", typeof(int));
Dcolumn1.AutoIncrement = true;
Dcolumn1.AutoIncrementSeed = 1;
Dcolumn1.AutoIncrementStep = 1;
Dtable.Columns.Add(Dcolumn1);
Dtable.Columns.Add("Employeename", typeof(s开发者_如何学Gotring));
Dtable.Columns.Add("NoofDays", typeof(int));
this datatable is binded to a gridview.
how can i rearrange the order of the datatable.ie..if row no 2 is deleted then row no 3 must become row no 2..like that.
thanks in advance.
in T-SQL, you can use turn off identity insert - this should allow you to update the identity values with sequential values.
the commands are:
SET IDENTITY_INSERT table ON
--update records here
SET IDENTITY_INSERT table OFF
just replace table with the table you are working on.
You should reseed the table when you are done.
There are a bunch of other things to consider (like foreign keys, index fragmentation etc) when doing this, and unless you have a compelling reason, I wouldn't recommend it.
精彩评论