?
Solved

sort adotables

Posted on 2001-09-13
4
Medium Priority
?
1,387 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 200 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

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