日期:2014-05-18  浏览次数:20945 次

用Provider=SQLOLEDB.1方式连接数据库,recordcount返回-1
在编写程序时,同样的查询语句,数据库为mssql2k,当数据源为driver={SQL   Server};recordcount返回正常值;
当数据源为Provider=SQLOLEDB.1;同样sql语句返回recordcount=-1,一直解决不了这个问题。

Public   strSQLUser   As   String   'SQL用户名
Public   strSQLPW   As   String   'SQL密码
Public   strSQLDB   As   String   'SQL数据库
Public   cnMain   As   New   adodb.Connection       '主连接
Dim   sql   As   String
Dim   rs   As   New   adodb.Recordset
strSQL   =   "driver={SQL   Server};server= "   &   strServer   &   ";user   id= "   &   strUser   &   ";password= "   &   strPass
sql   =   "select   *   from   editor   where   users= ' "   &   Trim(txtUserName.Text)   &   " ' "
cnMain.Open   strSQL
rs.Open   sql,   cnMain,   adOpenKeyset,   adLockPessimistic,   adCmdText
      If   rs.RecordCount   >   0   Then   //rs.recordcount返回值正常
当strSQL改为:
  strSQL   =   "Provider=SQLOLEDB.1;server= "   &   strServer   &   ";user   id= "   &   strUser   &   ";password= "   &   strPass
sql   =   "select   *   from   editor   where   users= ' "   &   Trim(txtUserName.Text)   &   " ' "
cnMain.Open   strSQL
rs.Open   sql,   cnMain,   adOpenKeyset,   adLockPessimistic,   adCmdText
      If   rs.RecordCount   >   0   Then   //rs.recordcount=-1
请问各位高手,这个问题可能出在哪里,我该如何解决!比较棘手


------解决方案--------------------
rs.CursorLocation = 3 设置这个属性
rs.Open ....