Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi guys,

When i delete any value from database , i want to reorder the primary key again ..

how can i do it ?

for example

ID NAME
1 JOHN
2 SEVINC
3 ALI
4 OSMAN
5 FEYZA
6 CIHAT

FOR INSTANCE , if i delete 4th person Osman from database , in my access database , it converts

ID NAME
1 JOHN
2 SEVINC
3 ALI
5 FEYZA
6 CIHAT

BUT I WANA DO NEW ORDER LIKE

ID NAME
1 JOHN
2 SEVINC
3 ALI
4 FEYZA
5 CIHAT

HOW CAN I DO IT ?
Posted
Updated 15-Sep-12 6:03am
v2
Comments
[no name] 15-Sep-12 11:41am    
You use DBCC CHECKIDENT and what on earth does this have to do with C#?
beratxt 15-Sep-12 11:58am    
in access program , is there some option to do it ? i use c# , db is access
[no name] 15-Sep-12 12:00pm    
http://support.microsoft.com/kb/812718
Vinod Viswanath 15-Sep-12 12:12pm    
It will lead to confusions.,Dnt do it.
beratxt 15-Sep-12 12:34pm    
i know but what is your suggestion for the data which wants to be deleted from listBox control.?

I choose the item in listBox control then i get the index of the item , then , i select from database where id = listBoxSelectedIndex..then i try to delete ? how can it be easy ? ..

short ly , i want to delete (the item which is selected on listBox )from db ? coz after deleting process , when i add something , the index of the value in database doesnt change but new item in listbox changes..

Primary keys are meant to be used for joining tables together and indexing, they are not meant to be used for human usage. Reordering primary key columns could orphan data and wreck havoc to your queries.

Add another column to your table and reorder that column to your will (show that column to your user instead of the primary key).
 
Share this answer
 
Comments
beratxt 15-Sep-12 12:49pm    
thanks you..how can i delete the data from database that are chosen in the listBox control ? if i select from database according to the item name located in the listBox , i may use different two or more same name ....if i select from database according to index of the item..it works , but when i add new item to the listBox , it is added .but the index of the new item and the new ID of item in database is DIFFERENT..HOW ?
Hi,

No need to rearrange the Primary key, ListBox has two properties( value and text), bind the primary key field(ID) to value property and rebind the grid after deleting the records.

this.listBox1.DataSource = listToBind ;
this.listBox1.DisplayMember = "Text";
this.listBox1.ValueMember = "Id";

You can retrieve the selected value using the property.

ListBox1.SelectedValue

Hope this will help you.

Thanks!!!
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900