POPULATE A TSTRINGLIST WITH DATA READ IN FROM AN ODBC TABLE

I have to modify a legacy Delphi program to populate a TStringList with data taken from an ODBC source.  

The ODBC DSN is called EXCHEQUER and I wish to populate a TStringlist with the idxStockCode field of all the rows read in from the StockCode table.  I have set the connectionstring for the  ADOConnection1 control but that is as far as I have got.  The connection string is  : Provider=MSDASQL.1;Persist Security Info=False;Data Source=EXCHEQUER;Mode=Read

I am not a Delphi programmer and so I need step by step help please - that's why its 250 points.

Charles CB
ccravenbartleAsked:
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.

mikelittlewoodCommented:
Drop an ADOQuery onto the form and link it to the ADOConnection.

In the SQL property put the query

SELECT idxStockCode
FROM SotckCode

Now do something like this with the stringlist and the query

Try
  // create stringlist
  StringList1 := TStringList.Create;
  // open query
  ADOQuery1.Open
  //Loop through the query
  While not ADOQuery1.eof do
  begin
    // add item to stringlist
    StringList1.Add( ADOQuery1.FieldByName('idxStockCode').AsString );
    // move to next record
    Next;
  end;
Finally
  // Close the query
  ADOQuery1.Close;
End;
0
mikelittlewoodCommented:
Make sure your ADOConnection is active

ADOConnection1.Connected := True;
0
mikelittlewoodCommented:
Spotted mistake,

Next

Should say

ADOQuery1.Next
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
ccravenbartleAuthor Commented:
THANKS - JOB DONE!
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.