BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Sort a specific field of a DB

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (Desktop)
View previous topic :: View next topic  
Author Message
Marcello Scala
Guest





PostPosted: Wed Feb 11, 2004 12:35 pm    Post subject: Sort a specific field of a DB Reply with quote



Hi All.
I have this problem:

I have a Table with this fields:

Id, Name, Number.

The filed ID is AutoInc and is the Key.

If i have this data:

1, Marcello, 1
2, Marcello, 2
3, Marcello, 3
4, Marcello, 4
5, Marcello, 5
6, Bob, 1
7, Bob, 2
8, Bob, 3
9, Bob, 4

and i delete the record with id number 4, will have this data:

1, Marcello, 1
2, Marcello, 2
3, Marcello, 3
5, Marcello, 5
6, Bob, 1
7, Bob, 2
8, Bob, 3
9, Bob, 4

Now, how can i sort the ID field of the entire table and how can i sort only
the filed "Number" of data "Marcello"?

In this mode:

1, Marcello, 1
2, Marcello, 2
3, Marcello, 3
4, Marcello, 4
5, Bob, 1
6, Bob, 2
7, Bob, 3
8, Bob, 4

PS: without query (i use a 3rd partys DB Component and the TQuery support is
not good for now) but only with Locate method.

Thanks
Marcello



Back to top
Jayme Jeffman Filho
Guest





PostPosted: Wed Feb 11, 2004 1:58 pm    Post subject: Re: Sort a specific field of a DB Reply with quote



Hello,

If I understood you are using a TTable like component.

The TTable component needs a indexed database table to set a special order on the records. Once you deleted a record of the table, there is no any method to renumber the auto-inc field. A primary key must not be updated or the relational integrity will be lost - this is a rule for good database design. You can get the records ordered as before, although the field values are not the record number. You can use the RecNo property to get the record number in the data set ( not in the table !).

You can add a calculated field to the TTable and make its value equal to the TTable->RecNo property using the OnCalcFields event to use it in a DBGrid component. Without this calculated field you wont be able to present the record numbers to the user using a DBGrid.

HTH

Jayme.

"Marcello Scala" <mscala (AT) emails (DOT) it> wrote

Quote:
Hi All.
I have this problem:

I have a Table with this fields:

Id, Name, Number.

The filed ID is AutoInc and is the Key.

If i have this data:

1, Marcello, 1
2, Marcello, 2
3, Marcello, 3
4, Marcello, 4
5, Marcello, 5
6, Bob, 1
7, Bob, 2
8, Bob, 3
9, Bob, 4

and i delete the record with id number 4, will have this data:

1, Marcello, 1
2, Marcello, 2
3, Marcello, 3
5, Marcello, 5
6, Bob, 1
7, Bob, 2
8, Bob, 3
9, Bob, 4

Now, how can i sort the ID field of the entire table and how can i sort only
the filed "Number" of data "Marcello"?

In this mode:

1, Marcello, 1
2, Marcello, 2
3, Marcello, 3
4, Marcello, 4
5, Bob, 1
6, Bob, 2
7, Bob, 3
8, Bob, 4

PS: without query (i use a 3rd partys DB Component and the TQuery support is
not good for now) but only with Locate method.

Thanks
Marcello





Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (Desktop) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.