BCB中ADO数据库的TADOConnection连接
2021/11/21 19:41:11
本文主要是介绍BCB中ADO数据库的TADOConnection连接,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
//->->H
#ifndef Unit_GlobalH
#define Unit_GlobalH
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
#endif
#include "vcl.h"
#include
#include
#include "inifiles.hpp"class TGlobal
{
public:
TGlobal();
~TGlobal();
public:
TADOQuery * adoQuery;
TADOConnection * adoCon;
void InitDatabaseConnect () ;
int PerformSQL(AnsiString strSQL ,int exMode);
void AQEdit(AnsiString strSQL);
} ;
//->->CPP//-------------------------------------------------------------------------------------------------------------------------------------------------------------
#pragma hdrstop
#include "Unit_Global.h"
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
#pragma package(smart_init)
TGlobal::TGlobal()
{
adoQuery = new TADOQuery (NULL);
adoCon = new TADOConnection(NULL);
InitDatabaseConnect();
}
TGlobal::~TGlobal()
{
if(adoQuery)
delete adoQuery;
if(adoCon)
delete adoCon;
}
void TGlobal::InitDatabaseConnect ()
{
AnsiString database,user,password,catalog; // ,cathlabid
TIniFile *ini;
AnsiString siniFile = ExtractFilePath (Application->ExeName) + "config.ini";
if(FileExists(siniFile))
{
ini = new TIniFile(siniFile);
database =ini->ReadString( "setting", "database","");
user= user=ini->ReadString( "setting", "user","");
password=ini->ReadString( "setting", "password","");
catalog=ini->ReadString( "setting", "catalog","");adoCon->LoginPrompt=false;
AnsiString DMSQL = "Provider=SQLOLEDB.1;Password=""+password+"";Persist Security Info=True;User ID="+user+";Initial Catalog="+catalog+";Use Procedure for Prepare=1;Auto Translate=True;PadoConket Size=4096;Data Source="+database+";";
adoCon->ConnectionString = DMSQL;
adoCon->ConnectionTimeout=1000;
adoCon->Connected = true;
if(!adoCon->Connected)
{
Application->MessageBox("Database:Reason:InitDatabaseConnect","Error",MB_OK+MB_ICONERROR);
Application->Terminate();
}adoQuery->Connection = adoCon;
delete ini;
}}
int TGlobal::PerformSQL(AnsiString strSQL ,int exMode)
{
int nReturnValue = ->1;
TADOQuery * tempQuery = new TADOQuery(NULL);
tempQuery->Close();
tempQuery->Connection = adoCon;
tempQuery->SQL->Text = strSQL;
if(exMode==0)//查找 select
{
tempQuery->Open();
nReturnValue = tempQuery->RecordCount;
}
if(exMode==1)//插入,更新 insert update
{
tempQuery->ExecSQL();
}
delete tempQuery;
tempQuery = NULL;
return nReturnValue;
}
这篇关于BCB中ADO数据库的TADOConnection连接的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-01使用 SVN合并操作时,怎么解决冲突的情况?-icode9专业技术文章分享
- 2025-01-01告别Anaconda?试试这些替代品吧
- 2024-12-31自学记录鸿蒙API 13:实现人脸比对Core Vision Face Comparator
- 2024-12-31自学记录鸿蒙 API 13:骨骼点检测应用Core Vision Skeleton Detection
- 2024-12-31自学记录鸿蒙 API 13:实现人脸检测 Core Vision Face Detector
- 2024-12-31在C++中的双端队列是什么意思,跟消息队列有关系吗?-icode9专业技术文章分享
- 2024-12-31内存泄漏(Memory Leak)是什么,有哪些原因和优化办法?-icode9专业技术文章分享
- 2024-12-31计算机中的内存分配方式堆和栈有什么关系和特点?-icode9专业技术文章分享
- 2024-12-31QT布局器的具体使用原理和作用是什么?-icode9专业技术文章分享
- 2024-12-30用PydanticAI和Gemini 2.0构建Airflow的AI助手