- 綠色版查看
- 綠色版查看
- 綠色版查看
- 綠色版查看
調(diào)用方法
準(zhǔn)備工作:
登錄數(shù)據(jù)庫,點(diǎn)擊生成,將DBComm文件夾復(fù)制到使用程序目錄,在cpp文件頭添加如下:
#include ".DBCommDBTablesMyInfoOperator.h"
#include ".DBCommDBTablesRecordOperator.h"
#include ".DBCommDBTablesRecordViewOperator.h"
#include ".DBCommDBComm.h"
點(diǎn)擊“工程”菜單,選擇“添加到工程”,將DBComm內(nèi)所有cpp文件添加(包含DBTables下cpp文件)
調(diào)用示例
連接數(shù)據(jù)庫
void __fastcall TForm1::FormCreate(TObject *Sender)
{
WideString wstrConnStr="Provider=SQlolEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=mytest";
if(DBComm::Instance().ConnectDB(wstrConnStr))
{
DBGrid1->DataSource=DBComm::Instance().Tables<RecordViewOperator>(DBComm::RecordView)->Source();
}
}
新增一條記錄
void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
DBComm::Instance().Tables<MyInfoOperator>(DBComm::MyInfo)->New(LabeledEdit2->Text,LabeledEdit3->Text.ToDouble(),"admin",Now());
}
}
刪除一條記錄
void __fastcall TForm1::SpeedButton3Click(TObject *Sender)
{
if(DBGrid1->DataSource->DataSet->RecordCount)
{
int nID=DBGrid1->DataSource->DataSet->Fields->Fields[0]->AsInteger;
String strCondition="ID="+String(nID);
DBComm::Instance().Tables<RecordOperator>(DBComm::Record)->Delete(strCondition);
}
}
更新一條記錄
void __fastcall TForm1::SpeedButton2Click(TObject *Sender)
{
if(DBGrid1->DataSource->DataSet->RecordCount)
{
int nID=DBGrid1->DataSource->DataSet->Fields->Fields[1]->AsInteger;
String strName=LabeledEdit2->Text;
float fMoney=LabeledEdit3->Text.ToDouble();
String strCondition="ID="+String(nID);
DBComm::Instance().Tables<MyInfoOperator>(DBComm::MyInfo)->Update(strName,fMoney,"admin",Now(),strCondition);
}
}
獲取數(shù)據(jù)源
DBGrid1->DataSource=DBComm::Instance().Tables<RecordViewOperator>(DBComm::RecordView)->Source();
您的評論需要經(jīng)過審核才能顯示
有用
有用
有用