Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Post to Table, then sort records

Status
Not open for further replies.

troyu

Programmer
Nov 21, 2000
185
CA
I would like to be able to post string records to a table, but then after they have been posted to the table, to be sorted in ascending sequence.

Is this possible, despite the fact that the records are being posted to a string field?

I am posting the range of records as integers (I think)... I use the FieldByName.asInteger property when posting.

Any ideas?
 
String fields will always sort alphabetically, which with numbers will give you something like 1,11,12,2,3,etc. You could pad with zeros and so save them like 0001,0002,0003,0004, etc.

FieldByName('YourField').AsString := Format('%4d',[intvariable]);

TealWren
 
But when I do a select * on the table, I get the following: It doesn't appear that this should sort like this. Any thoughts?

SerialNumber
------------
500004
500019
500020
500001
500002
500007
500010
500013
500014
500015
500016
500017
500018
500023
500024
500003
500009
500012
500021
500022
500006
500008
500011
500025
500005
 
Are you doing order by serialnumber? It should be something like select * from table order by SerialNumber.

TealWren
 
Yes, I know how to do that in SQL, but I would like to do something in Delphi to sort the table in a similar way after posting my records to the table
 
As far as I'm aware, refreshing your query would be the only way to apply the sort to a TQuery dataset. It also depends on the kind of database and dataset you are using - for example, I have seen records move to their appropriate place in the sort order (primary key) using ADO and MSSQL, but I have used other BDE datasets which leave the new record at the end of the dataset.

You might be able to use a TClientDataset and the IndexFieldNames property to do that, although I've not done that myself.

Good Luck!
TealWren
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top