View Single Post
  #1  
Old 12-03-2006, 04:22 PM
struct struct is offline
Senior Member
 
Join Date: Nov 2003
Posts: 667
Default Getting Distict from ADOTable

I'm trying to populate a combobox with all the "languages" in my database. the problem is, this field has the same value for multiple rows. in sql you can use select distict to only return one of each value. how do i do this with an adotable?

[DELPHI]procedure TForm1.LoadLanguageBox();
begin
ADOTable1.Connection := ADOConnection1;
ADOTable1.TableName := 'Snippits';
ADOTable1.Open;
with ADOTable1 do
begin
First;
ListBox1.Items.Clear;
while not eof do
begin
ListBox1.Items.Add(FieldByName('Language').AsStrin g);
Next;
end;
end;
ADOTable1.close;
end;

// I tried this, but I don't think it's the write
// approch... it's not working and there has
// to be an easier way.
procedure TForm1.LoadLanguageBox();
var I : Integer;
begin
ADOTable1.Connection := ADOConnection1;
ADOTable1.TableName := 'Snippits';
ADOTable1.Open;
with ADOTable1 do
begin
First;
ListBox1.Items.Clear;
while not eof do
begin
For I := 0 to Listbox1.Count - 1 do
begin
If FieldByName('Language').AsString <>
Listbox1.Items.ValueFromIndex[I] then
ListBox1.Items.Add(FieldByName('Language').AsStrin g);
end;
Next;
end;
end;
ADOTable1.close;
end;[/DELPHI]

Code:
I love this forum!
function LearnSomethingNew(User:String):Boolean;
Reply With Quote