DBGrid to TXT Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiDB/html/delphi_20061222172931157.html
I want to use the ADO control, please provide details Code ?
If you want to export data quickly, you can use the dbgrideh control or cxgrid, which provides the export function.
Without controls, you can create a TXT file and write and export the file by yourself,
DM. dataset. savetofile ('C: \ my files. dbt', pfadtg );
// You can customize the exported file extension, but you may not understand the content. To export standard text, you can export it to an XML file ~!
If you want to save it as XML, pfxml will be used later.
For Loop write txt
While not datamodule1.adoquery. EOF do
Begin
N1: = datamodule1.adoquery. fieldbyname ('qjhzd'). asstring;
N2: = datamodule1.adoquery. fieldbyname ('bhzd'). asstring;
N3: = datamodule1.adoquery. fieldbyname ('bc1'). asstring;
N4date: = datamodule1.adoquery. fieldbyname ('rqzd'). asdatetime;
N4: = datetostr (n4date );
N5: = datamodule1.adoquery. fieldbyname ('sjzd'). asstring;
Txtstr: = ''+ N1 +'' + ',' + ''+ N2 +'' + ',' + ''+ N3 +'' + ', '+ ''+ N4 +'' +', '+ ''+ N5 + '';
Assignfile (F, savepath );
Append (f );
Writeln (F, txtstr );
Closefile (f );
Datamodule1.adoquery. Next;
End;
This is a method I have used. I hope it will be helpful to you.
I want to display about 40 fields. Do I need to define 40 variables?
Do you need other methods?
You can add the
For I: = 0 to fieldcount-1 do
Linesstr: = linesstr + fields [I]. asstring + ','; so no variable needs to be defined!
There is a problem with writing the file above. Opening and closing the file should not appear in the loop body. The preparation is started at the beginning of the loop, and the preparation is closed after the loop is completed.