⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.cpp

📁 C++ BUILDER精彩编程实例集锦(源码)3 第五部分 系统编程 第六部分 数据库应用
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "MainForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{ //创建源表
   this->Table1->Close();
   this->Table1->DatabaseName="C:";
   this->Table1->TableName="Table1.db";
   this->Table1->TableType=ttParadox;
   this->Table1->FieldDefs->Clear();
   TFieldDef *pNewDef = Table1->FieldDefs->AddFieldDef();
   pNewDef->Name = "No";
   pNewDef->DataType = ftString;
   pNewDef->Required = true;
   pNewDef->Size = 15;
   Table1->IndexDefs->Clear();
   Table1->IndexDefs->Add("","No", TIndexOptions() <<ixPrimary << ixUnique);
   this->Table1->FieldDefs->Add("Name",ftString,12,true);
   this->Table1->FieldDefs->Add("Sex",ftString,2,true);
   this->Table1->FieldDefs->Add("Dept",ftString,24,true);
   this->Table1->CreateTable();
   this->Table1->Open();
   this->Table1->AppendRecord(OPENARRAY(TVarRec,
("2004100701","王彬","男","轻工机械")));
   this->Table1->AppendRecord(OPENARRAY(TVarRec,
("2004100702","汪兰","女","轻工机械")));
   this->Table1->AppendRecord(OPENARRAY(TVarRec,
("2004100703","刘功德","男","轻工机械")));
   this->Table1->AppendRecord(OPENARRAY(TVarRec,
("2004100704","汤栏兰","女","幼师")));
   this->Table1->AppendRecord(OPENARRAY(TVarRec,
("2004100705","汤小敏","男","国际贸易")));
   this->Table1->AppendRecord(OPENARRAY(TVarRec,
("2004100706","罗成","女","农机")));
   this->Table1->AppendRecord(OPENARRAY(TVarRec,
("2004100707","汤波","男","农业种植")));

}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{//创建目标表
   this->Table2->Close();
   this->Table2->DatabaseName="C:";
   this->Table2->TableName="CopyData.db";
   this->Table2->TableType=ttParadox;
   this->Table2->FieldDefs->Clear();
   this->Table2->FieldDefs=this->Table1->FieldDefs;
   Table2->IndexDefs->Clear();
   Table2->IndexDefs->Add("","No", TIndexOptions() <<ixPrimary << ixUnique);
   this->Table2->CreateTable();
   this->Table2->EmptyTable();
   this->Table2->Open();
   this->BatchMove1->Source=this->Table1;
   this->BatchMove1->Destination=this->Table2;
   this->BatchMove1->Mappings->Clear();
   this->BatchMove1->Mode=batAppend;
  // this->BatchMove1->RecordCount=2;
   this->BatchMove1->Execute();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{//批修改数据
   this->BatchMove1->Source=this->Table1;
   this->BatchMove1->Destination=this->Table2;
   this->BatchMove1->Mappings->Clear();
   this->BatchMove1->Mode=batAppendUpdate;
  // this->BatchMove1->RecordCount=2;
   this->BatchMove1->Execute();
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -