配置一下ado组件的connectionstring属性

解决方案 »

  1.   

    如果你用的数据库是用odbc连接的或者干脆就是微软的数据库,
    那就可以不用bde了;反之?哈,当然要bde了!至于如何连接,
    我曾经问过同样的问题,搜一下,好吗?
      

  2.   

    ado连数据库很简单,找本入门的DELPHI数据库书就可以了
    至于发布的话,象楼上老兄说的那样,若用BDE可以用打包工具一样轻松解决。
      

  3.   

    用ado控件不需要bde的,
    至于连接数据库,在窗体或数据模板上放一个TAdoConnection控件,然后设置它的ConnectionString属性,然后将所有的AdoTable或AdoQuery或AdoDataSet的Connection属性设为AdoConnection1
      

  4.   

    ADO连接是不需要BDE的
    不过建议你把连接串的参数写注册表里
    这样如果要把程序移植到另一台机器只要改一下注册表就可以了
      

  5.   

    给你一个例子
    uses Registry
    procedure TrdmUserStudy.RemoteDataModuleCreate(Sender: TObject);
    var
      regConn : TRegistry;
      strConn : String;
      sProvider : String;
      sPersist : String;
      sUserID : String;
      sPassword : String;
      sCatalog : String;
      sDS: String;
      sPrepare : String;
      sTranslate : String;
      sPacketSize : String;
      sWorkStation : String;
      sEncryption : String;
      sTag : String;
    begin
      //开始构造连接串
      //从注册表中读取连接参数
      regConn := TRegistry.Create;
      try
        regConn.RootKey := HKEY_CURRENT_USER;
        regConn.OpenKey('\Software\IEdu',False);
        sProvider := regConn.ReadString('Provider');
        sPersist := regConn.ReadString('Persist Security Info');
        sUserID := regConn.ReadString('User ID');
        sPassword := regConn.ReadString('Password');
        sCatalog := regConn.ReadString('Initial Catalog');
        sDS := regConn.ReadString('Data Source');
        sPrepare := regConn.ReadString('Use Procedure for Prepare');
        sTranslate := regConn.ReadString('Auto Translate');
        sPacketSize := regConn.ReadString('Packet Size');
        sWorkStation := regConn.ReadString('Workstation ID');
        sEncryption := regConn.ReadString('User Encryption for Data');
        sTag := regConn.ReadString('Tag with column collation when possible');
      finally
        regConn.Free;
        strConn := 'Provider=' + sProvider + ';Persist Security Info=' + sPersist + ';User ID=' +
        sUserID + ';Password=' +  sPassword + ';Initial Catalog=' + sCatalog + ';Data Source=' +
        sDS + ';Use Procedure for Prepare=' + sPrepare + ';Auto Translate=' + sTranslate + ';Packet Size=' +
        sPacketSize + ';Workstation ID=' + sWorkStation + ';User Encryption for Data=' + sEncryption +
        ';Tag with column collation when possible=' + sTag;
      end;  connMain.ConnectionString := strConn;
      connMain.Connected := True;
    end;
      

  6.   

    给你一段C++buider的代码,一样的,参考一下把
    void __fastcall TPubData::DataModuleCreate(TObject *Sender)
    {   String User   ,Password ,Dsn,Database,ServerName;
       String ConnStr;
       String IniFile = ExtractFilePath(Application->ExeName) + "BarServer.ini";   Dsn  =  F_ReadProfileStr(IniFile,"DataBase","Dsn","netbar");
       Password = F_ReadProfileStr(IniFile,"DataBase","Password","");
       User = F_ReadProfileStr(IniFile,"DataBase","User","sa");
       Database = F_ReadProfileStr(IniFile,"DataBase","Database","netbar");
       ServerName= F_ReadProfileStr(IniFile,"DataBase","ServerName","127.0.0.1");
       ConnStr  = "Provider=SQLOLEDB;Password=" + Password
        + " ;Persist Security Info=True;  User Id=" + User  +  "; PassWord=" + Password  +   ";Remote Server = " + ServerName + ";Initial Catalog="  +  Database + ";";   try
            {
              PubData->PubConn->Connected=false  ;
              PubConn->ConnectionString=   ConnStr;
              PubData->PubConn->Connected=true ;
              IdTypeQuery->Active=true;
              MechineStatusQuery->Active=true;
              MechineRegionQuery ->Active=true;
              UserLevelQuery->Active=true;          }
              catch(Exception &e)
              {           F_TellError(Application->Handle,"连接数据库失败!"  + e.Message);
               Application->Terminate();           }
      

  7.   

    你只要明白有兩種方式和數據庫相連
       dbe和ado
      你只能選其一.然後找入門的書看看就明白了.
      

  8.   

    老虎用的好像是INI文件
    一样的道理
    都是把参数写进去。然后在程序中读出参数,把连接串拼出来,赋给TADOConnection.ConnectionString
      

  9.   

    楼上高分的老兄:
        用ado真的不需要bde吗?我怎么听人说用ado连接oracle需要bde啊??
    是不是中间有什么误会?讲清楚好吗?
      

  10.   

    连Oracle是不是用dbExpress也可以
    我没有做过,不是很清楚,望高手指点