如何对包含空格的字段名称对ADO表进行排序? [英] How Can I Sort an ADO Table on a Fieldname Containing a Space?

查看:218
本文介绍了如何对包含空格的字段名称对ADO表进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Delphi,但这是一个简单而一般的问题:

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

我正在做以下操作:

var
  ArticlesTable: TADOTable;

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

这个工作非常好,可以让我有效地处理记录,当他们进来时,CITY字段。

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.

然而,现在我想按字段LAST NAME在其中有一个嵌入的空间进行排序。但是当我使用语句:

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';

我收到错误讯息:

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

我看过关于SORT字符串语法的帮助。它说要用逗号分隔多个字段,并在字段之后添加ASC或DESC以对升序或降序进行排序。但是,如果一个字段名称中有一个空格,它不会说怎么办。

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.

我已经尝试将字段名称放在单引号和双引号中,甚至使用# 20作为空格字符,但那些不起作用。

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.

我无法更改Microsoft Access数据库中的字段名称,因为还有其他程序我不

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]';

这篇关于如何对包含空格的字段名称对ADO表进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆