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

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 myfield,ass;
  19.   if(!OpenDialog1->Execute())return;
  20. //Query1初始化
  21.   Query1->Active=False;
  22.   Query1->SQL->Clear();
  23.   Query1->SQL->Add("select *");
  24.   ass="from ""+OpenDialog1->FileName+""";
  25.   Query1->SQL->Add(ass);
  26.   Query1->Active=True;
  27. //Table1初始化
  28.   Table1->Active=False;
  29.   Table1->TableName=OpenDialog1->FileName;
  30.   Table1->EmptyTable();
  31.   Table1->Active=True;
  32. //复制记录
  33.   while(!Query1->Eof)
  34.   {
  35.     Table1->Append();
  36.     for(ii=0;ii<Query1->FieldCount;ii++)
  37.     {
  38.       myfield=Table1->Fields->Fields[ii]->FieldName;
  39.       switch(Table1->Fields->Fields[ii]->DataType)
  40.       {
  41.         case ftString:
  42.           Table1->FieldByName(myfield)->AsString=Query1->FieldByName(myfield)->AsString;
  43.           break;
  44.         case ftSmallint:
  45.         case ftInteger:
  46.         case ftWord:
  47.           Table1->FieldByName(myfield)->AsInteger=Query1->FieldByName(myfield)->AsInteger;
  48.           break;
  49.         case ftBoolean:
  50.           Table1->FieldByName(myfield)->AsString=Query1->FieldByName(myfield)->AsString;
  51.           break;
  52.         case ftFloat:
  53.           Table1->FieldByName(myfield)->AsFloat=Query1->FieldByName(myfield)->AsFloat;
  54.           break;
  55.         case ftCurrency:
  56.           Table1->FieldByName(myfield)->AsCurrency=Query1->FieldByName(myfield)->AsCurrency;
  57.           break;
  58.         case ftDate:
  59.         case ftTime:
  60.         case ftDateTime:
  61.           Table1->FieldByName(myfield)->AsDateTime=Query1->FieldByName(myfield)->AsDateTime;
  62.           break;
  63.         default:
  64.           break;
  65.       }
  66.     }
  67.     Table1->Post();
  68.     Query1->Next();
  69.   }
  70. }
  71. //---------------------------------------------------------------------------