?? uadoset.pas
字號:
begin
end;
prepared;
Open;
if RecordCount<>0 then
begin
Result:=FieldByName(FieldName).AsVariant;
end;
end; //with
Finally
AdoQuery.Close;
end;
end;///
/////得到符合條件的記錄的個數(shù)////////////////////////
Function getRecordCount(AdoQuery:TAdoQuery;strSql:string;paramValues:TStringList):integer;
var
i:integer;
begin
///FieldName:=TStringList.Create;
try
with Adoquery do
begin
ConnectionString:=ConnectToDatabase(2);
try
close;
except
ON E:Exception do
begin
exit;
end;
end;
sql.clear;
///strSql:='SELECT * FROM '+TableName+' WHERE '+FieldName+'=:'+FieldName;
Sql.Text:=strSql;
for i:=0 to paramValues.count-1 do
begin
Parameters[i].value:=paramValues[i];
end;
prepared;
Open;
if RecordCount<>0 then
begin
Result:=recordcount;
end
else
Result:=0;
end; //with
Finally
AdoQuery.Close;
end;
end;////Function
///////判斷符合條件的記錄是否存在/////////////////////////////////
Function isRecordExist(AdoQuery:TAdoQuery;strSql:string;paramValues:TStringList):Boolean;
var
i:integer;
begin
///FieldName:=TStringList.Create;
try
with Adoquery do
begin
ConnectionString:=ConnectToDatabase(2);
try
close;
except
on E:exception do
begin
showmessage('hjhjhjhj');
exit;
end;
end;
sql.clear;
///strSql:='SELECT * FROM '+TableName+' WHERE '+FieldName+'=:'+FieldName;
Sql.Text:=strSql;
for i:=0 to paramValues.Count-1 do
begin
Parameters[i].value:=paramValues[i];
end;
prepared;
Open;
if RecordCount<>0 then
begin
Result:=true;
end
else
Result:=false;
end; //with
finally
AdoQuery.Close;
end;
end;///
//////設(shè)置檢索參數(shù)條件的數(shù)量/////////////////
//Function setParamsCount(params:TStringList):TStringList;
//begin
// result:=params;
//end;/////
/////實現(xiàn)操作函數(shù)的定義//////////////
Function GetConnectString(iFlag:integer;Section:string;Keyword:string):string;
var
MyIni:TIniFile;
DbName:string;
begin
/////建立一個Ini文件的實例////////////////////
////ExtractFilePath(Application.exename)應(yīng)用程序的當(dāng)前目錄/////////////
MyIni:=TIniFile.Create(ExtractFilePath(Application.ExeName)+'\PlugIns\ConnectString.Ini');
if iFlag=1 then
begin
if MyIni.ValueExists(Section,Keyword) then
begin
DbName:=MyIni.ReadString(Section,Keyword,'');
end;//if
end;////if
if iFlag=2 then
begin
if MyIni.ValueExists(Section,Keyword) then
begin
DbName:=MyIni.ReadString(Section,Keyword,'');
end;//if
end;////if
MyIni.Free;
result:=DbName;
end;////
////////連接數(shù)據(jù)庫函數(shù)/////
Function ConnectToDatabase(iFlag:integer):String;
begin
///CurrentPath:=GetConnectionString();
if iFlag=1 then ////1:代表本地數(shù)據(jù)庫2:代表SqlServer數(shù)據(jù)庫////
begin
result:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+GetConnectString(iFlag,'LocalDb','DbName')+';Persist Security Info=False';
end;
if iFlag=2 then
begin
//if iDBFlag=1 then
//begin
///showmessage(GetConnectString(iFlag,iDbFlag,'DbName'));
//showmessage('a');
result:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog='+getConnectString(iFlag,iDbFlag,'DbName')+';Data Source=NTSERVER';
//end;
end;
end;
procedure FillCtrlParam(AdoQuery:TAdoQuery;strSql:string;paramValues:TStringList;ctrl:TControl;FieldName:string);
var
i:integer;
Node,Node1:TTreeNode;
begin
////////填充下拉框控件combobox/////////////////////////////
if (ctrl is TCombobox) then
begin
TCombobox(ctrl).Clear;
try
with AdoQuery do
begin
ConnectionString:=ConnectToDatabase(2);
try
Close;
except
ON E:exception do
begin
exit;
end;
end;
Sql.Clear;
Sql.Text:=strsql;
if paramValues.Count<>0 then
begin
for i:=0 to paramValues.count-1 do
begin
Parameters[i].value:=paramValues[i];
end;
end;
prepared;
open;
if recordcount<>0 then
begin
while not eof do
begin
TCombobox(ctrl).Items.Add(FieldByName(FieldName).AsString);
next;
end;///while
end;//if
end;///with
Finally
AdoQuery.Close;
end;
end;///ifTv
////////填充目錄樹控件Treeview/////////////////////////////
if (Ctrl is TTreeView) then
begin
Node:=TTreeView(Ctrl).Items[0];
//Node:=TTreeView(TV).Selected;
try
with AdoQuery do
begin
ConnectionString:=ConnectToDatabase(2);
try
Close;
except
ON E:exception do
begin
exit;
end;
end;
Sql.Clear;
Sql.Add(strSql);
prepared;
open;
if recordcount<>0 then
begin
while not eof do
begin
node1:=TTreeView(Ctrl).Items.AddChild(Node,FieldByName(FieldName).AsString);
next;
end;///while
end;//if
end;///with
Finally
AdoQuery.Close;
end;
end;///ifTv
end;////
////將某一個字段的內(nèi)容填充到一個控件中////////////////////////////////
////**TV控件名稱////////////////////////
///**TableName表名/////////////////////
////**FieldName字段名稱//////////////////
procedure FillControl(AdoQuery:TAdoQuery;Tv:TControl;TableName:string;FieldName:string);
var
Node,Node1:TTreeNode;
strSql:string;
begin
strsql:='Select distinct '+FieldName+' From '+TableName;
////////填充目錄樹控件Treeview/////////////////////////////
if (TV is TTreeView) then
begin
Node:=TTreeView(Tv).Items[0];
//Node:=TTreeView(TV).Selected;
try
with AdoQuery do
begin
ConnectionString:=ConnectToDatabase(2);
try
Close;
except
ON E:exception do
begin
exit;
end;
end;
Sql.Clear;
Sql.Add(strSql);
prepared;
open;
if recordcount<>0 then
begin
while not eof do
begin
node1:=TTreeView(Tv).Items.AddChild(Node,FieldByName(FieldName).AsString);
next;
end;///while
end;//if
end;///with
Finally
AdoQuery.Close;
end;
end;///ifTv
////////填充下拉框控件combobox/////////////////////////////
if (TV is TCombobox) then
begin
TCombobox(Tv).Clear;
try
with AdoQuery do
begin
ConnectionString:=ConnectToDatabase(2);
try
Close;
except
ON E:exception do
begin
exit;
end;
end;
Sql.Clear;
Sql.Add(strSql);
prepared;
open;
if recordcount<>0 then
begin
while not eof do
begin
TCombobox(Tv).Items.Add(FieldByName(FieldName).AsString);
next;
end;///while
end;//if
end;///with
Finally
AdoQuery.Close;
end;
end;///ifTv
////////填充下拉框控件combobox/////////////////////////////
if (TV is TListBox) then
begin
TListBox(Tv).Clear;
try
with AdoQuery do
begin
ConnectionString:=ConnectToDatabase(2);
try
Close;
except
ON E:exception do
begin
exit;
end;
end;
Sql.Clear;
Sql.Add(strSql);
prepared;
open;
if recordcount<>0 then
begin
while not eof do
begin
TlistBox(Tv).Items.Add(FieldByName(FieldName).AsString);
next;
end;///while
end;//if
end;///with
Finally
AdoQuery.close;
end;
end;///ifTv
////////////////////////////////////////////////////////////
end;//////FillControl//////////////////
///////////////////////////////////////////////////////////////////////////
end.
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -