• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 404
  • Last Modified:

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
0
Paul-Brooks
Asked:
Paul-Brooks
1 Solution
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now