Combobox does not return columns from SqlServer

1

In the following code, it should present me the columns of a table that I have in my system, but when clicking to display the options in the combobox nothing appears. However, if I start typing the name of the field, for example, Name_ it is complete with Social_Name and displays the result correctly.

the code:

        cbbColunas.Items.Clear();
     with TADOQuery.Create(Self) do
         begin
     Connection := ADOConnection1; 
        SQL.Text := 'SELECT '+ ' c.name '+
         'FROM '+ ' Sys.Columns c '+
         'LEFT OUTER JOIN '+
         ' sys.index_columns ic ON ic.object_id = c.object_id AND ic.column_id = c.column_id '
        + 'LEFT OUTER JOIN '+
         ' sys.indexes i ON ic.object_id = i.object_id AND ic.index_id = i.index_id '
        + 'WHERE '+
         ' c.object_id = OBJECT_ID(:tabela)';
        Parameters.ParamByName('tabela').DataType := ftString; Parameters.ParamByName('tabela').Value := cbbTabelas.Text;
         Open();
         First(); 
        while not Eof do begin cbbColunas.Items.Add(FieldByName('name').AsString);
        Next(); 
        end; 
        end;
    
asked by anonymous 05.11.2015 / 19:25

1 answer

-1

Use the function below:

ADOConnection.GetFieldNames('NOME_DA_TABELA', cbbColunas.Items);
    
28.01.2016 / 16:03