Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:2k
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Unit1.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- int ii;
- AnsiString myfield,ass;
- if(!OpenDialog1->Execute())return;
- //Query1初始化
- Query1->Active=False;
- Query1->SQL->Clear();
- Query1->SQL->Add("select *");
- ass="from ""+OpenDialog1->FileName+""";
- Query1->SQL->Add(ass);
- Query1->Active=True;
- //Table1初始化
- Table1->Active=False;
- Table1->TableName=OpenDialog1->FileName;
- Table1->EmptyTable();
- Table1->Active=True;
- //复制记录
- while(!Query1->Eof)
- {
- Table1->Append();
- for(ii=0;ii<Query1->FieldCount;ii++)
- {
- myfield=Table1->Fields->Fields[ii]->FieldName;
- switch(Table1->Fields->Fields[ii]->DataType)
- {
- case ftString:
- Table1->FieldByName(myfield)->AsString=Query1->FieldByName(myfield)->AsString;
- break;
- case ftSmallint:
- case ftInteger:
- case ftWord:
- Table1->FieldByName(myfield)->AsInteger=Query1->FieldByName(myfield)->AsInteger;
- break;
- case ftBoolean:
- Table1->FieldByName(myfield)->AsString=Query1->FieldByName(myfield)->AsString;
- break;
- case ftFloat:
- Table1->FieldByName(myfield)->AsFloat=Query1->FieldByName(myfield)->AsFloat;
- break;
- case ftCurrency:
- Table1->FieldByName(myfield)->AsCurrency=Query1->FieldByName(myfield)->AsCurrency;
- break;
- case ftDate:
- case ftTime:
- case ftDateTime:
- Table1->FieldByName(myfield)->AsDateTime=Query1->FieldByName(myfield)->AsDateTime;
- break;
- default:
- break;
- }
- }
- Table1->Post();
- Query1->Next();
- }
- }
- //---------------------------------------------------------------------------