Dim conn As New ADODB.Connection
    Dim ret As New ADODB.Recordset
    
    Dim str_sql As String
    
    conn.ConnectionString = "Provider=SQLOLEDB.1;" & _
                            "Password=hrk;" & _
                            "Persist Security Info=True;" & _
                            "User ID=hrk;" & _
                            "Initial Catalog=HRK;" & _
                            "Data Source=."
    conn.Open
    
    str_sql = "SELECT xbm, lvbm, [2004-3-25] FROM t_sell1"
    
    ret.Open str_sql, conn, adOpenKeyset, adLockOptimistic
    
    If ret.RecordCount = -1 Then
        MsgBox ret.RecordCount
        Exit Sub
    End If
    
    ret.MoveFirst执行之后,ADO的记录集总是返回-1,这是为什么,是SQL Server的问题吗?
我用的是SQL Server 2000 sp3 + vb6.0 sp6 

解决方案 »

  1.   

    不能信任RecordCount的结果,因为这个结果需要你遍历了这个recordset后才能出来,一般你可以一直用movenext到结束,自己计算有多少。
      

  2.   

    这个问题已解决,在ret.open之前加入
    ret.CursorLocation = adUseClient
    就OK了,我太大意了,看看朋友们对这段程序还有什么其它的意见
      

  3.   

    大家也可以看看下面的这个,
    http://community.csdn.net/Expert/topic/3453/3453514.xml?temp=2.578372E-02