sql语句执行有结果~但是rs_tmp.RecordCount的值为-1,咋回事呢?Dim rs_tmp As New ADODB.Recordset        cn.ConnectionTimeout = 100
        cn.Open "Driver={Microsoft Visual FoxPro Driver};" & _
           "SourceType=DBC;" & _
           "SourceDB=" & txt_foxfile.Text & _
           ";Exclusive=No;"
        Set rs_tmp = cn.Execute("select a.编号,a.姓名,a.性别,a.民族,a.出生日期,a.工作单位,a.健康状况,a.文化程度,a.职业状况" & _
        ",a.人户状况 , a.户口性质, a.婚姻未报, a.婚姻状况, a.夫妻关系, a.母子关系, a.初婚时间, a.再婚时间, b.身份证号" & _
        ",b.独生子女证号,b.领证时间,b.退证时间 from 户内人口 a left join 已婚育妇 b on a.编号 = b.卡号 ")      
       
        MsgBox rs_tmp.RecordCount

解决方案 »

  1.   

    把游标类型设置为静态
    .CursorLocation = adUseClient
      

  2.   

    现象 
        ==== 
        当在服务器端请求RecordCoun时会返回-1。这是因为ActiveX Data Objects (ADO) 2.0中的CursorType是adOpenForwardonly或者adOpenDynamic。如果是ADO 1.5,只发生在cursortype是adOpenForwardonly的时候。如果使用OLEDB provider for JET和SQL Server产生的结果可能不同,这依赖于数据库的提供者。 
        提供者可能不支持某些CursorTypes。当你选择的CursorType不被支持时,提供者将选择最接近于你所请求的CursorType。请参考你的提供者的文档。此外,请注意不是所有的LockType和CursorType的组合都可以同时工作。改变LockType将强制改变CursorType。请确定使用调试来检查CursorType的值。 
         
        原因 
        ===== 
         
        在动态的游标中纪录号可能改变。Forward only的游标无法返回RecordCount。 
         
        解决办法 
        ========== 
        使用adOpenKeyset(=1)或者adOpenStatic(=3)作为服务器端游标或者客户端游标。客户端只使用adOpenStatic作为CursorTypes,而不管你选择什么样的CursorType。 
         
        状态 
        ====== 
         
        这个形式是设计决定的。 
         
        更多信息 
        ================ 
         
        重复行为的步骤 
        --------------------------- 
         
        1. Open a standard .exe project in Visual Basic. From the Project menu, choose References. Select either the Microsoft Active Data Object 1.5 Library or the Microsoft Active Data Object 2.0 Library. 
         
        2. Paste the following code in the form code window: 
         
         Option Explicit 
         Dim rs As ADODB.Recordset 
         
         Private Sub Form_Load() 
         'set up rs 
         Set rs = New ADODB.Recordset 
         rs.CursorLocation = adUseServer 
         rs.Open "Select ProductID from products", & _ 
         "Provider=Microsoft.Jet.OLEDB.3.51;" & _ 
         "Data Source=d:\vb5_win95\nwind.mdb", _ 
         adOpenDynamic, adLockUnspecified 
         
         Debug.Print rs.RecordCount 
         End Sub 
         
         3. Replace the preceding Data Source with a Data Source on your computer. Run the preceding form and note the record count. Change the CursorType to adOpenForwardonly and note the record count. 
         
         4. Change the CursorLocation to adUseClient and experiment with the different CursorTypes. In all cases the correct record count returns.
      

  3.   

    把游标类型设置为静态
    .CursorLocation = adUseClient或者用1,1方式打开