简体   繁体   中英

How to print data of _RecordSet to the text file in delphi 10

how to print all data/records contain in Recordset to the text file in Delphi 10 ? I could not able to find any Method or property for it.Please guide, i am newbie in delphi.

I have done following:

Var:
    CurrField : Field;
    RecSet:_RecordSet ;
Begin:
    RecSet:= command.Execute(records,Params,-1);
    CurrField := RecSet.Fields[0];
end;

but i want to print complete records/data contain in RecSet(_RecordSet type) in text file.

You can write it yourself. If the recordset is relatively small, the easiest way is to use a TStringList.

var
  i: Integer;
  s: string;
  SL: TStringList;
begin
  SL := TStringList.Create;
  try
    while not RecSet.Eof do
    begin
      // Clear string for the next row
      s := '';
      // Loop through the fields in this row, creating a comma-separated list
      for i := 0 to RecSet.FieldCount - 1 do
        s := s + RecSet.Fields[i].Value + ',';
      // Remove unnecessary final comma at end
      SetLength(s, Length(s) - 1); 
      // Add to the stringlist
      SL.Add(s);
    end;
    // Save the stringlist content to disk
    SL.SaveToFile('YourFileName.txt');
  finally
    SL.Free;
  end;
end;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM