使用 Delphi (Dbexpress) 获取列名称
我正在使用这个 sql 命令来获取列名:
select COLUMN_NAME from
INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = 'MyTableName'
但我不知道如何使用执行的 SQL 命令结果!
例如,这种方法无法将列名提取为字符串值,并且我收到此错误=不支持操作:
for i := 1 to Qry1.RecordCount do
begin
end;
I'm using this sql command to get column names :
select COLUMN_NAME from
INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = 'MyTableName'
but i don't know how can i using the executed SQL command results !
for example , this way doesn't work to extract the column names as a string value and i got this error = Operation Not Supported :
for i := 1 to Qry1.RecordCount do
begin
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
另一种方法是查询表本身以获取空数据集,然后循环访问该数据集中的字段。
像这样的查询将返回其中没有记录的表结构:
并且像这样的循环将迭代每个字段
Another way you can do this is to query the table itself to get an empty dataset, and then loop through the fields in that dataset.
A query like this will return the table structure with no records in it:
And a loop like this will iterate through each field
像这样的东西适用于 TADOQuery (不确定它对于 dbExpress 是否不同):
Something like this would work for a TADOQuery (not sure if it's different for dbExpress):
据我了解,您无法检索结果。
这是一段一直对我有用的代码
或者您可以阅读此链接,它解释了为什么在调用 .RecordCount (http://edn.embarcadero.com/article/28494)
总而言之,它表明您的查询区分大小写,您应该检查表名称(MyTableName)
From what I understand you are unable to retreive the retults.
This is a piece of code which has always worked for me
Or you can read this link which explains why the exception is thrown when calling .RecordCount (http://edn.embarcadero.com/article/28494)
To sum it up it suggests that your query is case-sensitive and you should probably check the table name (MyTableName)
同意 Rob McDonell 的观点,为了列出字段的列名称,我将使用它
就像在我的代码中我写了这样的东西
agree with Rob McDonell, in order to list the column name of a field, I'll use that
as in my code I wrote something like this