以编程方式查找 MS-Access 2007 表“字段索引”出席? TField.IsIndexedField 不起作用
我的表 Customers 有一个已索引的字段 UserID。
现在,当我从以下位置删除此字段时delphi,我将 EOleExecption 作为其索引字段。 我尝试使用以下代码:
ObjCustomers := TADOTable.Create(nil);
ObjCustomers.Connection := Connection;
ObjCustomers.TableName := 'Customers';
ObjCustomers.Open;
if (ObjCustomers.FindField('UserID').IsIndexField) then
begin
ExecuteSQLStatements(['DROP INDEX UserID ON Customers']);
end;
但是对于这种情况,这个 Tfield.IsIndexField 出现 False 。 此外,我不想做这样的事情:
try
ExecuteSQLStatements(['DROP INDEX UserID ON Customers']);
except
on E: exception do
end;
有什么方法可以让我在执行 SQL 查询之前检查该字段是否已索引?
提前谢谢!
My table Customers has a field UserID which is indexed.
Now when I am dropping this Field from delphi, I am getting EOleExecption as its a indexed field.
I tried with following code:
ObjCustomers := TADOTable.Create(nil);
ObjCustomers.Connection := Connection;
ObjCustomers.TableName := 'Customers';
ObjCustomers.Open;
if (ObjCustomers.FindField('UserID').IsIndexField) then
begin
ExecuteSQLStatements(['DROP INDEX UserID ON Customers']);
end;
But this Tfield.IsIndexField is coming up False for this case.
Further I dont wanna do something like this:
try
ExecuteSQLStatements(['DROP INDEX UserID ON Customers']);
except
on E: exception do
end;
Is there any way so that I can check whether the field is Indexed, before executing SQL query?
Thankx in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
GetIsIndexField
未由TADODataSet
实现,结果将为False
。使用 TADOConnection.OpenSchema 检索表索引:
要使此答案完整:
根据TLama的建议,您可以使用
TADODataSet
方法GetIndexNames
。ADO
在内部使用Command.ActiveConnection.OpenSchema(adSchemaIndexes...
GetIsIndexField
is not implemented byTADODataSet
, and the result will beFalse
.Use
TADOConnection.OpenSchema
to retrieves table indexes:To make this answer complete:
As suggested by TLama you can use the
TADODataSet
methodGetIndexNames
.ADO
is internally usingCommand.ActiveConnection.OpenSchema(adSchemaIndexes...
这对我在 DelphiXE2 上有用
This works for me on DelphiXE2