用ado 调用api。生成连接字符串可以吗?

解决方案 »

  1.   

    ADO有这个功能吗?还请详细解释,我查不到。
      

  2.   

    const
      ODBC_ADD_DSN        = 1;
      ODBC_CONFIG_DSN     = 2;
      ODBC_REMOVE_DSN     = 3;
      ODBC_ADD_SYS_DSN    = 4;
      ODBC_CONFIG_SYS_DSN = 5;
      ODBC_REMOVE_SYS_DSN = 6;function SQLConfigDataSource(hwndParent: Integer;
      fRequest: LongInt; lpszDriverString: string;
      lpszAttributes: string): LongBool; stdcall; external 'ODBCCP32.DLL';procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    const
      BoolStr: array[Boolean] of string = ('f', 't');
    begin
      if Key <> VK_RETURN then Exit;
      Caption := BoolStr[
        SQLConfigDataSource(0, ODBC_ADD_SYS_DSN,
    //                    ~换成Handle就是手工配置
    'SQL Server',                       //数据库类型
    'DSN=MyDatabase'#0 +                //数据源名称
    'Server=(local)'#0 +                //SQL Server服务器名
    'Database=DatabaseName'#0 +         //数据库名称
    'Description=动态配置ODBC'#0        //描述
        )];
    end;
      

  3.   

    oh yeah,谢谢 zswang(伴水)(破碎的心只剩下灵感) 大侠
      

  4.   

    再问一句!
    如何用程序添加 odbc 的access(*.mdb)数据源?