Click here to Skip to main content
14,636,049 members
Rate this:
Please Sign up or sign in to vote.
See more:
hello,
i have a problem..
i am creating c#.net windows based project using visual studio 2008 and ms sql server.
i want to rearrange my datatable after deletion.
i am explaining it...
(1) i have a table of Statecode,statename,year.
if i delete 1 state from all states,then statecode should be re-arrange.
as if statecode 1,2,3,4,5.and i delete 4th row then it becomes 1,2,3,5.
i want it to be 1,2,3,4.means 4 records starting from 1.

(2) if i will not take statecode as a primary key,then what is the
solution for this problem.

please reply.
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

khandelwal g wrote:
i want it to be 1,2,3,4.means 4 records starting from 1


Why do you want to do that? What's the need? It's not advisable. Generally applications does not work on single table. There are dependencies and foreign key relations. If you change a dependant column value in main table then you need to take care of other tables too.

There is no point in re-assigning the values. They are in DB and your application knows how to handle it.

Infact, primary keys most of the times are made an Identity Key to avoid any issue.


khandelwal g wrote:
if i will not take statecode as a primary key,then what is the
solution for this problem.

I don't find any problem out here? What's troubling you? Rearrangement is not going to help you, so why to do it!
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100