delphi10中如何将_RecordSet的数据打印到文本文件中
How to print data of _RecordSet to the text file in delphi 10
如何将Recordset中包含的所有data/records打印到Delphi10中的文本文件中?
我无法找到 it.Please 指南的任何方法或 属性,我是 delphi 的新手。
我做了以下事情:
Var:
CurrField : Field;
RecSet:_RecordSet ;
Begin:
RecSet:= command.Execute(records,Params,-1);
CurrField := RecSet.Fields[0];
end;
但我想在文本文件中打印完整的 records/data 包含在 RecSet(_RecordSet 类型)中。
你可以自己写。如果记录集相对较小,最简单的方法是使用 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;
如何将Recordset中包含的所有data/records打印到Delphi10中的文本文件中? 我无法找到 it.Please 指南的任何方法或 属性,我是 delphi 的新手。
我做了以下事情:
Var:
CurrField : Field;
RecSet:_RecordSet ;
Begin:
RecSet:= command.Execute(records,Params,-1);
CurrField := RecSet.Fields[0];
end;
但我想在文本文件中打印完整的 records/data 包含在 RecSet(_RecordSet 类型)中。
你可以自己写。如果记录集相对较小,最简单的方法是使用 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;