各位高手请问在Dll文件里如何编写Sql操作语句 我用的是Access数据库 使用ADO动态连接

解决方案 »

  1.   

    在Dll函数里面操作数据库吗,这个没有什么问题呀.
    你把要求说具体点,我给你写个函数.
      

  2.   

    Access数据库 使用ADO动态连接
    来实现对数据的增\删\改\查我现在郁闷的是使用动态连接数据库 都连不上
    后面的语句 也测试不出来 Dll 我刚学  对数据库操作 的写法 还不太明白 请指教
    谢谢
      

  3.   

      try
        CoInitialize(Nil);
        ADOQuery1:= TADOQuery.Create(nil);    try
         ADOConnection1.Close ;
          ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;'+'Data Source='+extractfilepath(application.ExeName)+'company.mdb;persist security info=false;';
       ADOConnection1.Open;
        ADOQuery1.Active:=False;
             ADOQuery1.Connection:=ADOConnection1;
     adoquery1.SQL.Clear;
       ADOQuery1.SQL.Text:='insert into qyInformation (qy_name,qy_introduction) values ("name","introduction")';
      ADOQuery1.Active:=True;   { ADOQuery1.SQL.add('insert into qyInformation');
     ADOQuery1.SQL.Add('(qy_name,qy_introduction)');
     ADOQuery1.SQL.add('values (:name,:introduction)'); 
    ADOQuery1.Parameters.ParamByName('name').Value:=a;
     ADOQuery1.Parameters.ParamByName('introduction').Value:=b ;}//---第二种插入方法
       
          try
       ADOQuery1.ExecSQL ;
       
         except  messagedlg('增加用户失败!'+chr(13)+'可能原因:用户名重复或其他数据不符合要求。',mtinformation,[mbok],0);
      exit;
         end;
      messagedlg('创建新用户成功!',mtinformation,[mbok],0);  finally
       ADOConnection1.Close;
        ADOQuery1.Close;  
    请问我这样写的问题在哪里?
      

  4.   

    主程序里面
    var
      adoc: TAdoConnection;
    begin
      adoc.ConnectString := ''//构建的Access 数据库的连接串
      adoc.LoginPrompt := False;
      adoc.Open;
      CallDll_insert(adoc,'a','b',1,2....);//dll里面的函数CallDll_insert,插入记录
      //....
    end;//======================================
    //Dll函数:
    //申明:
    procedure CallDll_insert(adoc: TAdoConnection; a,b: string; i,j: integer;....);stdcall;//函数
    procedure CallDll_insert(adoc: TAdoConnection; a,b: string; i,j: integer;....);stdcall;
    var
      q: TAdoQuery;
    begin
      q := TAdoQuery.Create(nil);
      q.Connection := adoc;
      q.SQL.Clear;
      q.SQL.Add('insert into TABLENAME (字段列表) values (''' + a + ''',''' + b + ''',' + IntToStr(i) + ',' + IntToStr(i) + ',' + ... + ')');
      q.ExecSQL;
      q.Destroy;
    end;
    //其他更新\删除\等语句参照这个
      

  5.   

    try
        CoInitialize(Nil);
        ADOQuery1:= TADOQuery.Create(nil);    try
         ADOConnection1.Close ;
         //上边这行有问题,应该改成 if stOpen in ADOConnection1.State  then ADOConnection1.Close;
      

  6.   

    不用在Dll 文件里写  动态连接的 语句啊 
    你的方法我先试试 谢谢一会在联系
    你的QQ是多少?'shove'
    保持联系