Delphi动态链接多个数据源执行操作例子

发布时间:2020-07-25 05:49:20 作者:sunboy_zzc
来源:网络 阅读:491

1.首先配置文件
[SubExamDep1]
DBSERVER=(local)
DBNAME=herpeisweixin
USERNAME=sa
PWD=bjbr
MSG=SubExamDep1失败
[SubExamDep2]
DBSERVER=(local)
DBNAME=herpeisFZTJ
USERNAME=sa
PWD=bjbr
MSG=SubExamDep2失败
2.工程文件加入 Inifiles 文件
public:
MyIni :Tinifile;
glAppPath :string;
create 事件增加
glAppPath := ExtractFilePath(Application.ExeName);//获取当前运行程序的路径
MyIni := Tinifile.Create(glAppPath + 'SubDBConfig.ini');

初始化表单增加
with spSP_SyncOrg do
begin

  ProcedureName:='P_SYNCORGINF';
  Parameters.CreateParameter('@ID_Org', ftInteger, pdInput, 0,null );
  Parameters.CreateParameter('@ID_OrgReservation', ftInteger, pdInput, 0, null);
  Parameters.CreateParameter('@RetMsg',ftString,pdOutput,50,null)
end;

    实现按钮事件
    procedure TFormPeisOrgReservation.btn_IssuedSubClick(Sender: TObject);

var
i:Integer;
DBSERVER,DBNAME,USERNAME,PWD:string;
CurSecetion:string;
CURID_ORG,CURID_OrgReservation :Integer;
MSG,retMSG,SumMsg:string;
sucessnum:Integer;

begin
MSG:='';
retMSG:='';
SumMsg:='';

if not aqMain1.Active then
begin
  Exit;
end;
lst1.Clear;
CURID_ORG:=aqMain1.fieldbyname('ID_Org').Value;
CURID_OrgReservation:=aqMain1.fieldbyname('ID_OrgReservation').Value;
sucessnum:=0;
MyIni.ReadSections(lst1.Items);
for i:=0 to lst1.Count-1 do
begin
  CurSecetion:=lst1.Items[i];
  DBSERVER:=MyIni.ReadString(CurSecetion,'DBSERVER','');
  DBNAME:=MyIni.ReadString(CurSecetion,'DBNAME','');
  USERNAME:=MyIni.ReadString(CurSecetion,'USERNAME','');
  PWD:=MyIni.ReadString(CurSecetion,'PWD','');
  MSG:=MyIni.ReadString(CurSecetion,'MSG','');

   try
      ADOConnection1SUB.Connected:=False;
      ADOConnection1SUB.ConnectionString:='Provider=SQLOLEDB.1;Password='+PWD+';Persist Security Info=True;User ID='+USERNAME+';Initial Catalog='+DBNAME+';Data Source='+DBSERVER;
      ADOConnection1SUB.Connected:=True;
      spSP_SyncOrg.Parameters.ParamByName('@ID_ORG').Value:=CURID_ORG;
      spSP_SyncOrg.Parameters.ParamByName('@ID_OrgReservation').Value:=CURID_OrgReservation;
      spSP_SyncOrg.ExecProc;
      retMSG:=spSP_SyncOrg.Parameters.ParamByName('@RetMsg').Value;

      if retMSG='同步成功!' then
      begin
          sucessnum:=sucessnum+1;
      end;

      if retMSG='同步失败!' then
      begin
         if SumMsg='' then
         begin
            SumMsg:=MSG;
         end
         else
         begin
            SumMsg:=SumMsg+','+MSG;
         end;

      end;

   except
   end;

end;
if sucessnum=lst1.Count then
begin
   ShowMessage('同步成功!');
end
else
begin
   if SumMsg='' then
   begin
      ShowMessage('执行失败!');
   end
   else
   begin
      ShowMessage(SumMsg);
   end;
end;

end;

界面放一个adoconnection和listbox控件

推荐阅读:
  1. delphi浮动窗口
  2. shell 脚本应用《八》多个脚本命令例子

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

delphi 动态链接 执行操作

上一篇:Nagios的安装配置与应用之二Nagios配置前的排错

下一篇:Numpy的简单用法

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》