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

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
0
ccravenbartle
Asked:
ccravenbartle
  • 3
1 Solution
 
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
 
ccravenbartleAuthor Commented:
THANKS - JOB DONE!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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