Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Access NoEffort
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 15-Sep-12 6:40am
beratxt706
Edited 15-Sep-12 7:03am
Wes Aday94.3K
v2
Comments
Wes Aday at 15-Sep-12 11:41am
   
You use DBCC CHECKIDENT and what on earth does this have to do with C#?
beratxt at 15-Sep-12 11:58am
   
in access program , is there some option to do it ? i use c# , db is access
Wes Aday at 15-Sep-12 12:00pm
   
http://support.microsoft.com/kb/812718
Vinod Viswanath at 15-Sep-12 12:12pm
   
It will lead to confusions.,Dnt do it.
beratxt at 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..
Joan Murt at 15-Sep-12 14:26pm
   
This is a bad idea, don't do it, you'll have to go along all the different tables and relations of the other related tables and you'll be in trouble, better separate the visualization...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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).
  Permalink  
Comments
beratxt at 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 ?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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!!!
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,078
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 15 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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