'这个简单
'引用 ODBC Driver & Data Source Name Functions
Dim x As New ODBCTool.Dsn
x.CreateDSN ....

解决方案 »

  1.   

    建立 Access 数据源
    ===========================================================
      Option  Explicit
      Private  Declare  Function  SQLDataSources  Lib  "ODBC32.DLL"  (ByVal  henv&  ,  ByVal  fDirection%,  ByVal  szDSN$,  ByVal  cbDSNMax%,  pcbDSN%,  ByVal  szDescription$,  ByVal  cbDescriptionMax%,  pcbDescription%)  As  Integer
      Private  Declare  Function  SQLAllocEnv%  Lib  "ODBC32.DLL"  (env&  )
      Const  SQL_SUCCESS  As  Long  =  0
      Const  SQL_FETCH_NEXT  As  Long  =  1
      Public  shujupath  As  String
      '用代码配置mdb数据库
      Sub  info()
      Dim  strdescription,  strattributes
      On  Error  GoTo  aa
      Dim  lg  As  Long
      Dim  de  As  DBEngine
      Set  de  =  New  DBEngine
      strdescription  =  "试验数据源"  '描述
      Dim  aa  As  String
      aa  =  appstr  &    "db\db.mdb"
      strattributes  =  "dbq="  &    aa  &    _
      vbCr  &    "description="  &    strdescription  &    _
      vbCr  &    "Fil=ms  access"  &    _
      vbCr  &    "uid="  &    "password="
      
      de.RegisterDatabase  "shuju",  "microsoft  access  driver  (*.mdb)",  True,  strattributes
      Exit  Sub
      aa:
      MsgBox  "调试失败"
      End  Sub
      

  2.   

    利用DAO和RDO都可以DAO为:DBEngine.RegisterDatabase 
    RDO为:rdoRegisterDataSource具体使用方法可参见MSDN
      

  3.   

    to dbcontrols
      给个简单的例子
      

  4.   

    来源于:www.vbguide.com.tw
    Private Const ODBC_ADD_DSN = 1           ' Add data source
    Private Const ODBC_CONFIG_DSN = 2     ' Configure (edit) data source
    Private Const ODBC_REMOVE_DSN = 3   ' Remove data source
    Private Const vbAPINull As Long = 0&       ' NULL PointerPrivate Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" _
    (ByVal hwndParent As Long, ByVal fRequest As Long, _
    ByVal lpszDriver As String, ByVal lpszAttributes As String) As Long
    Named Pripes
    Public Sub CreateDSN(sDSN As String)
        Dim nRet As Long
        Dim sDriver As String
        Dim sAttributes As String
        sDriver = "Oracle73 Ver 2.5"
        sAttributes = "Server=Oracle8" & Chr$(0)
        sAttributes = sAttributes & "DESCRIPTION=" & sDSN & Chr$(0)
        'sAttributes = sAttributes & "DSN=" & sDSN & Chr$(0)
        sAttributes = sAttributes & "DATABASE=DBFinance" & Chr$(0)
        sAttributes = sAttributes & "Userid=Scott" & Chr$(0)
        'sAttributes = sAttributes & "PWD=myPassword" & Chr$(0)
        DBEngine.RegisterDatabase sDSN, sDriver, True, sAttributes                                '爹
        'nRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, sDriver, sAttributes)  '爹
    End SubPublic Sub DeleteDSN(sDSN As String)
        Dim nRet As Long
        Dim sDriver As String
        Dim sAttributes As String
        sDriver = "Oracle73 Ver 2.5"
        sAttributes = sAttributes & "DSN=" & sDSN & Chr$(0)
        nRet = SQLConfigDataSource(vbAPINull, ODBC_REMOVE_DSN, sDriver, sAttributes)
    End Sub
      

  5.   

    另一个:http://www.vbguide.com.tw/howto/500/0474.asp