Delphi and SQL

New to Delphi and SQL and am stuck on somthing very basic.
I have a combobox connected to an SQL table. The SQL populates the combobox and this works fine. Only problem is, and it is an anoying one, when i use the drop down on the combobox i get a blank line before the info i am expecting. Looking at the SQL table the last loine is always blank so i believe it is picking up this line and sending it to my combobox.
Any suggestions to make it stop
Paul BrooksAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Imthiyaz_phCommented:
r u using a Query or a Table component?

try using a Query component and filter out the blank line using the Where clause.
0
geobulCommented:
Hi,

Is this a TComboBox and you have code loop (function or something) for filling its Items from a db table? In this case you can trim the field value, check if the result is not empty and add it to the box. If the result is empty do not add it.

Or maybe it's TDBLookupComboBox?

Regards, Geo
0
Paul BrooksAuthor Commented:
I am using a SQL component and using the string list editir to select * from my SQL table. Have tried using "where is not null" with no success
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

geobulCommented:
And the reason for that empty line to appear on top is because (most probably) your TComboBox.Sorted property is set to true.
0
Paul BrooksAuthor Commented:
Geo
Think you hit the nail on the head, your solution sounds right but how to do implement it. As i said very new at this, just me and a big book
0
geobulCommented:
Well, it would be easier to correct your own code for filling the box if you post it here. I assume you've got something like:

procedure TForm1.Something(..);
begin
  ComboBox1.Items.Clear;
  ADOQuery1.Open;
  while not ADOQuery1.Eof do begin
    ComboBox1.Items.Add(ADOQuery1.FieldByName('Filed1').AsString);
    ADOQuery1.Next;
  end;
  ADOQuery1.Close;
end;

And that code might be changed to:

procedure TForm1.Something(..);
var
  s: string;
begin
  ComboBox1.Items.Clear;
  ADOQuery1.Open;
  while not ADOQuery1.Eof do begin
    s := Trim(ADOQuery1.FieldByName('Filed1').AsString);
    if s <> '' then  ComboBox1.Items.Add(s);
    ADOQuery1.Next;
  end;
  ADOQuery1.Close;
end;

Regards, Geo
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ivanov_GCommented:
"where is not null" - it will not work if you have a space in the column

select * from table
where trim(field1) != ""

I don't know what Database you use, but in most of them you have TRIM function, which acts the same way as in Delphi - it strips the spaces in the beginning and end of string.

Example: Str = "__MyColumn__"    (where _ is space)
   Trim(Str) = "MyColumn"
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.