Solved

sort adotables

Posted on 2001-09-13
4
1,380 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

Independent Software Vendors: 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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

696 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