DBGrid to txt

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.