Combobox does not return Sqlserver columns

Asked

Viewed 59 times

1

In the following code, it should present me the columns of a table I have on 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 Nome_it completes with Name_rsocial 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;
  • And this code presented is being called where ?

  • onchange of the combobox

  • where I am can not run Delphi, there on Where where you are searching for the parameter, try to use a LIKE. Question, need to use the parameter ?

  • I can try with the Like, at lunch I test and return here

  • It didn’t work, what intrigues me is that if I type some text in the combo, the columns appear, but if I click them they do not fill the combo.

  • I decided to put the code in onmouseenter, is not the right but solves my case at the moment.

  • Strange, the chance should already work! But I’m glad you found a solution!

  • I fully agree, I tested the version of Delphi tested in 2 different. and continued.. I will leave there maybe someone give me a light.

  • The onchange event is triggered when you start typing something, it would not be simpler for you to use a Dbcombobox with all the data already filled?

Show 4 more comments

1 answer

-1

Use the function below:

ADOConnection.GetFieldNames('NOME_DA_TABELA', cbbColunas.Items);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.