怎样在程序中建立ODBC的连接? 在线等!急急!!
前面我已经看了类似的帖子(由mizuhata发的),并且按照大头河马的代码去连接SQL Server数据库。代码如下:
    Dim sAttributes As String
   nRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, "SQL
Server", "DSN=JJJ") ’这一句是成功的。
    sAttributes = "Server=jdycserver"
    sAttributes = sAttributes & "DESCRIPTION="
    sAttributes = sAttributes & "DSN=JJJ"
    sAttributes = sAttributes & "DATABASE=xchk"
    nRet = SQLConfigDataSource(vbAPINull, ODBC_CONFIG_DSN = 2, "SQL Server", sAttributes)‘这一句始终返回值为零。并且发现ODBC中JJJ的 Server=JJJ,DSN=JJJ,DESCRIPTION="",DATABASE=xchk.
    Set cnn = New ADODB.Connection
    cnn.ConnectionString = "DSN=JJJ"
    cnn.Open
    Set rst = New ADODB.Recordset
    rst.Open "select * from StudInfo", cnn, adOpenDynamic, adLockOptimistic, -1
  请高手指教。

解决方案 »

  1.   

    '--------------
        
                     Set rstCmms = New ADODB.Recordset
                        With rstCmms
                            .CursorType = adOpenDynamic
                            .CursorLocation = adUseClient
                            .LockType = adLockOptimistic
                            .Source = "select * from tblaccount "
                        Set .ActiveConnection = cnn
                            .Open
                        End With
                    Set adodc1.Recordset = rstCmms---------
    '----------------
      

  2.   

    Public cn  As New ADODB.Connection
        cn.ConnectionString = "provider=SQLOLEDB;server=www;uid=sa;pwd="
        cn.CursorLocation = adUseClient
        cn.Open
      

  3.   

    Dim cnn As ADODB.Connection
    Dim rs As ADODB.Recordset
    ---------------------------------------------------Set con = New ADODB.Connection
    cnn1.Open "provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Bookstore;Data Source=192.168.0.250;"'Bookstore 为数据库名Set rs = New ADODB.Recordset
    rs.Open "StudInfo", con, adOpenDynamic, adLockOptimistic'StudInfo 为数据表名
      

  4.   

    何必一定用ODBC用ado+oledb驱动不好么
      

  5.   

    我的意思是:怎样在系统的ODBC中,建立一个SQL 的数据库的连接,并不是怎样用ADODB连接已经创建好的数据库连接???