日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

面向过程的ado建造者模式

發(fā)布時(shí)間:2023/12/9 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 面向过程的ado建造者模式 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

{*******************************************************}
{?????????????????????????????????????????????????????? }
{?????? ADO數(shù)據(jù)工廠???????????????????????????????????? }
{?????????????????????????????????????????????????????? }
{?????? 版權(quán)所有 (C) 2008 詠南工作室??????????????????? }
{?????????????????????????????????????????????????????? }
{*******************************************************}

unit uDataFactory;

interface

uses
? SysUtils,ADODB,DB,Classes,uCommFunc,ActiveX;

{ 生成連接對(duì)象 }
function GetADOConn(Owner:TComponent;AProvider:Integer=1):TADOConnection;
{ 生成數(shù)據(jù)集對(duì)象 }
function GetADODataSet(Owner:TComponent;AConn:TADOConnection;ASQL:string):TDataSet;
{ 執(zhí)行事務(wù)性SQL }
procedure UpdateADODataSet(Owner:TComponent;AConn:TADOConnection;ASQL:string);
{ 生成DataSource對(duì)象 }
function GetDataSource(Owner:TComponent):TDataSource;
{ 數(shù)據(jù)綁定 }
procedure LinkControl(ADataSet:TDataSet;ADataSource:TDataSource);

implementation

function GetDataSource(Owner:TComponent):TDataSource;
var
? FDataSource:TDataSource;
begin
? FDataSource:=TDataSource.Create(Owner);
? Result:=FDataSource;
end;?

procedure LinkControl(ADataSet:TDataSet;ADataSource:TDataSource);
begin
? ADataSource.DataSet:=ADataSet;
end;?

//==============================================================================
// AProvider=1 sql Server: 'sqloledb'
// AProvider=2 Access: 'Microsoft.Jet.OLEDB.4.0'
//==============================================================================

function GetADOConn(Owner:TComponent;AProvider:Integer=1):TADOConnection;
var
? Conn:TADOConnection;
? sFileName,sSection:string;
begin
? sFileName:=GetINIFile;
? Conn:=TADOConnection.Create(Owner);
? with Conn do
? begin
??? LoginPrompt:=False;
??? if AProvider=1 then
??? begin
????? Provider:='sqloledb';
????? sSection:='sql server';
????? Properties['Data Source'].Value:=ReadIniFile(sFileName,sSection,'server','');
????? Properties['User ID'].Value:=ReadIniFile(sFileName,sSection,'userid','');
????? Properties['Password'].Value:=ReadIniFile(sFileName,sSection,'password','');
????? Properties['Initial Catalog'].Value:=ReadIniFile(sFileName,sSection,'database','');
??? end;
??? if aprovider=2 then
??? begin
????? Provider:='microsoft.jet.oledb.4.0';
????? sSection:='access';
????? Properties['Jet OLEDB:Database Password'].Value:=ReadIniFile(sFileName,sSection,'database password','');
????? Properties['Data Source'].Value:=ReadIniFile(sFileName,sSection,'server','');
????? Properties['User ID'].Value:=ReadIniFile(sFileName,sSection,'userid','');
????? Properties['Password'].Value:=ReadIniFile(sFileName,sSection,'password','');
??? end;?
??? try
????? open;
????? Result:=Conn;
??? except
????? raise Exception.Create('數(shù)據(jù)庫(kù)連接失敗');
??? end;
? end;
end;

function GetADODataSet(Owner:TComponent;AConn:TADOConnection;ASQL:string):TDataSet;
var
? DataSet:TADODataSet;
begin
? dataset:=TADODataSet.Create(owner);
? dataset.Connection:=aconn;
? with dataset do
? begin
??? Close;
??? CommandText:='';
??? CommandText:=ASQL;
??? Open;
? end;
? Result:=DataSet;
end;?

procedure UpdateADODataSet(Owner:TComponent;AConn:TADOConnection;ASQL:string);
var
? FDataSet:TADOCommand;
begin
? FDataSet:=TADOCommand.Create(Owner);
? FDataSet.Connection:=AConn;
? AConn.BeginTrans;
? try
??? with FDataSet do
??? begin
????? CommandText:='';
????? CommandText:=ASQL;
????? Execute;
??? end;?
??? AConn.CommitTrans;
? except
??? AConn.RollbackTrans;
? end;
end;?

end.

轉(zhuǎn)載于:https://www.cnblogs.com/hnxxcxg/archive/2008/03/14/2941061.html

總結(jié)

以上是生活随笔為你收集整理的面向过程的ado建造者模式的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。