Solved

sort adotables

Posted on 2001-09-13
4
1,371 Views
Last Modified: 2007-12-19
hi,
i have many tables and when i open them in msaccess they are sorted ascending though opening them in delphi they arent.(note theres no index as such )
i just wish to sort the table ascending via the field named combobox1.text +' Title'.
(the active table in delphi is set via a combobox)

i looked at adotab1e.sort := combobox1.text +' Title');
but got various errors using it..though looking at the help file it should work..

Cheers Barry
0
Comment
Question by:inthe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 6

Accepted Solution

by:
wimmeyvaert earned 50 total points
ID: 6481583
I suppose you better use a ADOQuery instead.
There you can sort the data anyway you want, by filling
the SQL-Property like :

SELECT * FROM MyTable
ORDER BY MySortOrder

Best regards,
The Mayor
0
 
LVL 6

Expert Comment

by:wimmeyvaert
ID: 6481606
I tried to use an ADOTable and play a bit with the Sort-property.
I am able to sort the data on every field of the table.
I have a DBGrid on my form, linked to a ADOTable.
In the OnTitleClick-Event I use the following code :

procedure TForm1.DBGrid1TitleClick(Column: TColumn);
begin
  ADOTable1.Sort := Column.FieldName;
end;


This works fine for every field of my DBGrid.
What errors do you get ?

The Mayor.
0
 
LVL 6

Expert Comment

by:wimmeyvaert
ID: 6481625
Or even better,
(First declare a private unit-variable strPevSortField) :

procedure TForm1.DBGrid1TitleClick(Column: TColumn);
begin
  if Column.FieldName = strPevSortField then
    ADOTable1.Sort := Column.FieldName + ' ASC'
  else
    ADOTable1.Sort := Column.FieldName + ' DESC';
  strPevSortField := Column.FieldName;
end;


This way you give the user the possibility to sort the data DESC or ASC :
- First time he clicks a column the sortorder is ASC.
- Second time he clicks a column the sortorder is DESC.


The Mayor.
0
 
LVL 17

Author Comment

by:inthe
ID: 6482224
hi,
im not using a dbgrid only dbmemos and dbedits etc..
i tried it to see what happens and i get the following error:

Eoleexception with message arguments are of the wrong type, are out of
acceptable range,or are in conflict with one another.

the exception comes from ADODB.TCustomAdoDataSet.InternalSetSort function
i though because the field name is two words it caused it so i tried
ADOTable1.Sort := '"'+Column.FieldName+'"';  
ADOTable1.Sort := '['+Column.FieldName+']';
as i have used before in querys to get around spaces in field names but it produced same error.
if i add a showmessage(Column.FieldName); it shows correctly the fieldname.

i was thinking about it last night to change to adoquery mainly because the searching capibility of adotable is really useless for me..now it seems more like the thing to do.

(ie i want to search tables and return all results so i can step through them so if i had dbmemos only the search results would show when stepping through using dbnavigator etc..adotable1.Locate is only good at finding first instance.)


so i will change to adoquery and see how it goes.
cheers Barry
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question