📄 uadoset.pas
字号:
begin
end;
prepared;
Open;
if RecordCount<>0 then
begin
Result:=FieldByName(FieldName).AsVariant;
end;
end; //with
Finally
AdoQuery.Close;
end;
end;///
/////得到符合条件的记录的个数////////////////////////
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;///
//////设置检索参数条件的数量/////////////////
//Function setParamsCount(params:TStringList):TStringList;
//begin
// result:=params;
//end;/////
/////实现操作函数的定义//////////////
Function GetConnectString(iFlag:integer;Section:string;Keyword:string):string;
var
MyIni:TIniFile;
DbName:string;
begin
/////建立一个Ini文件的实例////////////////////
////ExtractFilePath(Application.exename)应用程序的当前目录/////////////
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;////
////////连接数据库函数/////
Function ConnectToDatabase(iFlag:integer):String;
begin
///CurrentPath:=GetConnectionString();
if iFlag=1 then ////1:代表本地数据库2:代表SqlServer数据库////
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;////
////将某一个字段的内容填充到一个控件中////////////////////////////////
////**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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -