English 中文(简体)
How Can I Sort an ADO Table on a Fieldname Containing a Space?
原标题:

I am using Delphi, but this is a simple and general problem:

I m doing the following:

var
  ArticlesTable: TADOTable;

begin
  ArticlesTable.DisableControls;
  ArticlesTable.Sort :=  CITY ;
  ArticlesTable.First;
  while not ArticlesTable.Eof do begin
    ...
    ArticlesTable.Next;
  end;

This works very well and allows me to efficiently process the records one by one with the records ordered ascending by the CITY field as they are coming in.

However, now I wanted to order by the field "LAST NAME" which has an embedded space in it. But when I use the statement:

  ArticlesTable.Sort :=  CITY ;

I get the error message:

  EOleException:  Arguments are of the wrong type, are out of acceptable range, 
                  or are in conflict with one another.

I have seen the help on the SORT string syntax. It says to separate multiple fields by commas, and to add ASC or DESC after a field to sort ascending or descending. But it doesn t say what to do if a fieldname has a space in it.

I ve tried putting the field name in single and double quotes and even using #20 as the space character, but those don t work.

I can t change the field name on the Microsoft Access database, because there are other programs I don t work with that depend on it.

I m sure there must be an easy way to do this that I don t know about.

最佳回答

Have you tried surrounding the fieldname by square brackets? for example:

ArticlesTable.Sort :=  [LAST NAME] ;
问题回答

暂无回答




相关问题
determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

Help with strange Delphi 5 IDE problems

Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How convert string to integer in Oxygene

In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签