Solved

sort adotables

Posted on 2001-09-13
4
1,353 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
  • 3
4 Comments
 
LVL 6

Accepted Solution

by:
wimmeyvaert earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now