Provider=SQLOLEDB.1;Password='+PWS+';Persist Security Info=True;User ID='+USERName+';Initial Catalog='+DBN+';Data Source='+Srv

解决方案 »

  1.   

    以下是我程序中一些代码拼出来的function myConnect( psd, login, server : string) : boolean;
    var at_tmp:TADOTable;
        ds_tmp:TDataSource;
        aq_tmp:TADOQuery;
        procedure freeAll();
        begin
          at_tmp.free;
          ds_tmp.free;
          aq_tmp.free;
        end;
    begin
    with DataModule1 do begin
      if ADOConnection1.Connected then ADOConnection1.Connected := false;     ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;' +
                                          'Password=' + psd + ';' +
                                          'User ID=' + login + ';' +
                                          'Persist Security Info=True;' +
                                          'Initial Catalog=zw;' +
                                          'Data Source=' + server;             ADOConnection1.LoginPrompt := false;
            try
                ADOConnection1.Connected :=true;
            except
                on e:Exception do begin
                    result := false;
                    exit;
                end
            end;  //*******************************
      at_tmp:=TADOTable.Create(nil);
      ds_tmp:=TDataSource.Create(nil);
      aq_tmp:=TADOQuery.Create(nil);
      at_tmp.Connection := ADOConnection1;
      at_tmp.TableName := 'SERVICE_DATA';
      at_tmp.Active := true;
      ds_tmp.DataSet := at_tmp;
      aq_tmp.Connection :=ADOConnection1;
      aq_tmp.DataSource := ds_tmp;
      //******************************
    end;  with aq_tmp do begin
        //..................
      end;
    end;
      

  2.   

    再改正一下function myConnect( psd, login, server : string) : boolean;
    var at_tmp:TADOTable;
        ds_tmp:TDataSource;
        aq_tmp:TADOQuery;
        procedure freeAll();
        begin
          at_tmp.free;
          ds_tmp.free;
          aq_tmp.free;
        end;
    begin
    with DataModule1 do begin
         if ADOConnection1.Connected then ADOConnection1.Connected := false; ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;' +
                                          'Password=' + psd + ';' +
                                          'User ID=' + login + ';' +
                                          'Persist Security Info=True;' +
                                          'Initial Catalog=zw;' +
                                          'Data Source=' + server;             ADOConnection1.LoginPrompt := false;
             try
                 ADOConnection1.Connected :=true;
             except
                 on e:Exception do begin
                     result := false;
            freeAll();
                     exit;
                 end
             end;   //*******************************
      at_tmp:=TADOTable.Create(nil);
      ds_tmp:=TDataSource.Create(nil);
      aq_tmp:=TADOQuery.Create(nil);
      at_tmp.Connection := ADOConnection1;
      at_tmp.TableName := 'SERVICE_DATA';
      at_tmp.Active := true;
      ds_tmp.DataSet := at_tmp;
      aq_tmp.Connection :=ADOConnection1;
      aq_tmp.DataSource := ds_tmp;
      //******************************
    end;  with aq_tmp do begin
        //..................
      end;
      
      result := true;
    end; 
      

  3.   

    多谢!
    在...之上 e:Exception确实开始 
    有 aq_tmp 的 确实开始 
    是什么语句,我是初学的,
      

  4.   


    re:Crob(我干嘛这么帅) 
     
    能不能发到[email protected]
    我很需要你这个代码!
      

  5.   

    自己先用ADO在DateModal上配置好,然后把ADOConnection1.ConnectionString赋值给一个String,进行断点调试,不就出来了吗?
      

  6.   

    ADO在DateModal
    在什么地方?
      

  7.   

    我这样做过:过程 TForm3.FormCreate(Sender: TObject ); 要怎么动态数据库的路径?
    开始 TADOTable1.connectionString:= 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=list.mdb;Mode=ReadWrite¦Share拒绝没有;坚持安全Llimitation Info=False' 
    //DataSource1.DatabaseName := ExtractFilePath(Application.ExeName) + 'list.mdb'; 结束;