Public Cn As ADODB.Connection
Set Cn = New ADODB.Connection
Cn.ConnectionString = "Provider=SQLOLEDB.1;" & _
                        "Persist Security Info=False;" & _
                        "User ID=sa;" & _
                        "Password=;" & _
                        "Database=DataBaseName;" & _
                        "Server=YourServerName"
Cn.Open

解决方案 »

  1.   

    dim cnstr as string  cnstr = "Provider = SQLOLEDB.1;Password=" + youpasd + ";Persist Security Info=True;User ID=sa;Initial Catalog=" + youdb + ";Data Data Source=" + youserver + ";"  
     用 adodc1:
      With adodc1
           .connectionstring = cnstr
           .username = "sa"
           .Password = youpasd 
           .RecordSource = yousql
           .Refresh
         End With或者用ADODB:
        Dim cnn1 As ADODB.Connection
        Dim rst1 As ADODB.Recordset
        Set cnn1 = New ADODB.Connection
        Call cnn1.Open(cnstr)
        Set rst1 = New ADODB.Recordset
        rst1.ActiveConnection = cnn1
        On Error GoTo errorhandle
        Call rst1.Open(yousql, cnn1, adOpenKeyset, adLockReadOnly)
        
       以上这样,不知是否满意?。。
      

  2.   

    建立ODBC连接DSN,如test然后:Dim Conn as new adodb.Connection
    Dim Rs as new adodb.RecordSet
    Conn.Open "DSN=test","sa",""Set Rs = Conn.Excute("查询字符串")if Not rs.eof() then