Board index » delphi » Converting result of query to stringlist

Converting result of query to stringlist

Hello,

I have the following question for you. Does there exist some easy way to
convert the result of a query into a tab (or comma) separated list? Or do I
have to loop through the whole list and simply add each record to a
stringlist??

What are your opinions on this?

Many thanks, Darius Blaszijk

 

Re:Converting result of query to stringlist


Have you tried DBGrid connected to this TQuery?

Quote
"Darius Blaszijk" <DBlasz...@ZonNet.nl> wrote in message

news:Lat56.8188$iB1.155660@zonnet-reader-1...
Quote
> Hello,

> I have the following question for you. Does there exist some easy way to
> convert the result of a query into a tab (or comma) separated list? Or do
I
> have to loop through the whole list and simply add each record to a
> stringlist??

> What are your opinions on this?

> Many thanks, Darius Blaszijk

Re:Converting result of query to stringlist


Ofcourse, but what I want is to export the result of a query into a richedit
text, where I can do syntax highlighting, and save any result to file. What
I want therefore is a tab or comma delimited result.

Darius Blaszijk

Quote
"wysza" <awy...@yahoo.com> wrote in message

news:KGu56.2185$bR3.436485@typhoon2.ba-dsg.net...
Quote
> Have you tried DBGrid connected to this TQuery?

> "Darius Blaszijk" <DBlasz...@ZonNet.nl> wrote in message
> news:Lat56.8188$iB1.155660@zonnet-reader-1...
> > Hello,

> > I have the following question for you. Does there exist some easy way to
> > convert the result of a query into a tab (or comma) separated list? Or
do
> I
> > have to loop through the whole list and simply add each record to a
> > stringlist??

> > What are your opinions on this?

> > Many thanks, Darius Blaszijk

Re:Converting result of query to stringlist


I don't know how rich you want your resultset to be shown, but you can
customize the drawing of any cell in a dbgrid using the OnDrawColumnCel
event.
Furthermore, if you are using a normal TQuery component, you could BatchMove
the resultset to a textfile. If you are using a TADOQuery, you could use the
SaveToFile method.

Karel

Quote
"Darius Blaszijk" <DBlasz...@ZonNet.nl> wrote in message

news:2HB56.8211$iB1.156415@zonnet-reader-1...
Quote
> Ofcourse, but what I want is to export the result of a query into a
richedit
> text, where I can do syntax highlighting, and save any result to file.
What
> I want therefore is a tab or comma delimited result.

> Darius Blaszijk

> "wysza" <awy...@yahoo.com> wrote in message
> news:KGu56.2185$bR3.436485@typhoon2.ba-dsg.net...
> > Have you tried DBGrid connected to this TQuery?

> > "Darius Blaszijk" <DBlasz...@ZonNet.nl> wrote in message
> > news:Lat56.8188$iB1.155660@zonnet-reader-1...
> > > Hello,

> > > I have the following question for you. Does there exist some easy way
to
> > > convert the result of a query into a tab (or comma) separated list? Or
> do
> > I
> > > have to loop through the whole list and simply add each record to a
> > > stringlist??

> > > What are your opinions on this?

> > > Many thanks, Darius Blaszijk

Re:Converting result of query to stringlist


No, you'll have to loop through every record. Example:

procedure ExportCSV(const DataSet: TDataSet; const FileName: String);
var
  F: TextFile;
  i: Integer;
  S: String;
begin
  DataSet.Open;
  try
    AssignFile(F, FileName);
    ReWrite(F);
    try
      S := '';
      for i := 0 to DataSet.FieldCount - 1 do
      begin
        if DataSet.Fields[i].Visible then
        begin
          if i > 0 then
            S := S + ',';
          S := S + '"' + DataSet.Fields[i].DisplayLabel + '"';
        end;
      end;
      WriteLn(F, S);
      while not DataSet.EOF do
      begin
        S := '';
        for i := 0 to DataSet.FieldCount - 1 do
        begin
          if DataSet.Fields[i].Visible then
          begin
            if i > 0 then
              S := S + ',';
            S := S + '"' + DataSet.Fields[i].DisplayText + '"';
          end;
        end;
        WriteLn(F, S);
        DataSet.Next;
      end;
    finally
      CloseFile(F);
    end;
  finally
    DataSet.Close;
  end;
end;

"Darius Blaszijk" <DBlasz...@ZonNet.nl> schreef in bericht
news:Lat56.8188$iB1.155660@zonnet-reader-1...

Quote
> Hello,

> I have the following question for you. Does there exist some easy way to
> convert the result of a query into a tab (or comma) separated list? Or do
I
> have to loop through the whole list and simply add each record to a
> stringlist??

> What are your opinions on this?

> Many thanks, Darius Blaszijk

Re:Converting result of query to stringlist


Hello

I think  you can use MIDAS (TClientDataSet.SaveToFile).
You can save data of query to file on disk and import data from
this file to StringList.

Yours sincerely
Vladimir Lubenchenko
mailto:l...@bazar.net
ICQ: 53906951

Quote
"Darius Blaszijk" <DBlasz...@ZonNet.nl> wrote in message

news:Lat56.8188$iB1.155660@zonnet-reader-1...
Quote
> Hello,

> I have the following question for you. Does there exist some easy way to
> convert the result of a query into a tab (or comma) separated list? Or do
I
> have to loop through the whole list and simply add each record to a
> stringlist??

> What are your opinions on this?

> Many thanks, Darius Blaszijk

Other Threads