Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:1k
源码类别:

VC书籍

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TForm1 *Form1;
  9. //---------------------------------------------------------------------------
  10. __fastcall TForm1::TForm1(TComponent* Owner)
  11.         : TForm(Owner)
  12. {
  13. }
  14. //---------------------------------------------------------------------------
  15. void __fastcall TForm1::Button1Click(TObject *Sender)
  16. {
  17.   int ii;
  18.   AnsiString fieldname;
  19.   if(!OpenDialog1->Execute())return;
  20. //Table1初始化
  21.   Table1->Active=False;
  22.   Table1->TableName=OpenDialog1->FileName;
  23. //  Table1->Active=True;
  24. //Table2初始化
  25.   Table2->Active=False;
  26.   Table2->TableName="~temp";
  27. //复制到临时文件
  28.   BatchMove1->Source=Table1;
  29.   BatchMove1->Destination=Table2;
  30.   BatchMove1->Mappings->Clear();
  31.   for(ii=0;ii<Table1->FieldCount;ii++)
  32.   {
  33.     fieldname=Table1->Fields->Fields[ii]->FieldName;
  34.     BatchMove1->Mappings->Add(fieldname);
  35.   }
  36.   BatchMove1->Mode=batCopy;
  37.   BatchMove1->Execute();
  38. //从临时文件拷回
  39.   Table1->Active=False;
  40.   Table1->EmptyTable();
  41.   BatchMove1->Source=Table2;
  42.   BatchMove1->Destination=Table1;
  43.   BatchMove1->Mode=batAppend;
  44.   BatchMove1->Execute();
  45. }
  46. //---------------------------------------------------------------------------