📄 unit1.cpp
字号:
//---------------------------------------------------------------------------
#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)
{
// String str;
///连接数据库
try
{
ADOConnection1->Connected=FALSE;
ADOConnection1->ConnectionString =String("Provider=Microsoft.Jet.OLEDB.4.0;")
+ "Data Source=" + ExtractFilePath(ParamStr(0)) + "db1.mdb;"
+ "Persist Security Info=False";
///不显示登陆对话框
ADOConnection1->LoginPrompt = False;
////开始连接数据集
ADOConnection1->Connected=TRUE;
//// 数据操作控件连接数据库
ADOQuery1->Connection=ADOConnection1;
/////数据源控件
DataSource1->DataSet=ADOQuery1;
////数据库数据感应控件
DBGrid1->DataSource=DataSource1;
}
catch(...)
{
ShowMessage("连接数据库错误");
}
// ShowMessage(str);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
ADOQuery1->Close();
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Text= "select * from 11月份";
// where 收货人='唐明光'
ADOQuery1->Open();
// ADOQuery1->Next();
// ADOQuery1->Fields->Fields[2]->AsString="鳌拜从";
// int shu=ADOQuery1->RecordCount; ///获取查询到的数据库纪录总数
// Label1->Caption=ADOQuery1->FieldByName("日期")->AsDateTime.DateString();
// int shu=ADOQuery1->FieldCount; ///获取数据库列数
// Label1->Caption=IntToStr(shu);
this->DBGrid1->Columns->Items[0]->Width=20;
this->DBGrid1->Columns->Items[1]->Width=40;
this->DBGrid1->Columns->Items[2]->Width=40;
this->DBGrid1->Columns->Items[3]->Width=40;
this->DBGrid1->Columns->Items[4]->Width=40;
this->DBGrid1->Columns->Items[5]->Width=40;
// Label1->Caption=DBGrid1->Fields[1]->AsString;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
// ADOQuery1->Close();
ADOQuery1->Edit(); ///数据库允许编辑
ADOQuery1->FieldByName("收货人")->AsString="鳌拜";
ADOQuery1->Post(); ////将更改后的数据写入数据库
// ADOQuery1->Open();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
ADOQuery1->Edit(); ///数据库允许编辑
ADOQuery1->FieldByName("日期")->AsDateTime=StrToDateTime("2007-10-1");
ADOQuery1->Post(); ////将更改后的数据写入数据库
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
ADOQuery1->Close();
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Text="Insert into 11月份 (日期,收货人,发货人,数量,重量,运费,转运) values ('2007-11-11','唐宁','本厂','2','620','62',null)";
ADOQuery1->ExecSQL();
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -