Search code examples
sqldelphidbexpress

Get Column names with Delphi (Dbexpress)


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;

Solution

  • Something like this would work for a TADOQuery (not sure if it's different for dbExpress):

    Qry1.Open;
    while not Qry1.Eof do begin
        // do whatever with Qry1.Fields[0].AsString here
        Qry1.Next;
    end;
    Qry1.Close;