////Ado
Dim StrCon As String
StrCon = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;" _
     & "Initial Catalog=你的数据库名称;Data Source=" & 你的IP地址 & ";" _
     & "Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;" _
     & "Use Encryption for Data=False;Tag with column collation when possible=False"
            
dim AcSys  as new adodb.connection 
   With AcSys
      If .State = adStateOpen Then .Close
      .ConnectionString = StrCon
      .ConnectionTimeout = 30
      .Open
    End With
///////

解决方案 »

  1.   

    ----------------------------------------------------vb代码
    dim ac_tmp    as new adodb.connection
    dim ar_tmp    as new adodb.recordset
    with ac_tmp
    ...
    ...
    end withtxtSQL = "select 名称 from 学生表 where 号码='"& combobox.text &"'"
    with ar_tmp
        if .state=adstateopen then .close
        .open txtSQL,ac_tmp,adopenkeyset,adlockreadonly
    end withif ar_tmp.recordcount>0 then
        text.text=ar_tmp!名称 
    else
        text.text=""
    endif
    ar_tmp.close
      

  2.   

    ///////DaoSet  qdserver=dbserver.CreateQueryDef(  "  ")  
    strSQL="EXEC  [SP]  @CODE_IN  =  'BATCHEXCHANGE'  "  
    With  qdserver  
         .Connect="odbc;driver={SQL  Server};database=datqbase;server=servername;pwd=123  "  
         .ReturnsRecords=True  
         .SQL  =  strSQL  
          Set  rsBatch=.OpenRecordset(dbOpenSnapshot,dbSQLPassThrough)  
    End  With
      

  3.   

    我想说简单了就是用ADO.或是DAO呀.
      

  4.   

    用ADO连接Sql server数据库
       
    strCN="Driver={SQL Server};Server=服务器名;DataBase=数据库;UID=用户;PWD=口令;"
     eg:SQL服务器名为 WEBSVR,数据库名为WebMis(在SQL Enterprise Manager中查看到),用户sa,口令123,则以上为: 
         
    dim cn as adodb.connection 
          set cn =new adodb.connection 
         dim strCn as string 
         strCN="Driver={SQL Server};Server=WEBSVR;DataBase=WebMis;UID=sa;PWD=123;" 
         cn.open strCN