Rs.CursorType = adOpenStatic
Rs.Open mysql, Adodc1.ConnectionString, 3, 3zje = Rs!总金额 & ""
zcc = Rs.RecordCount
Rs.Closemysql:"select sum(应收金额) as 总金额 from che where 时间>#2004-01# and 时间<#2004-02# and 车型='3' and 最大超限率<0.31"
mysql 应该没有问题, 因为 总金额每次都能算对, 但是zcc不是1就是-1,好奇怪
Rs.Open mysql, Adodc1.ConnectionString, 3, 3zje = Rs!总金额 & ""
zcc = Rs.RecordCount
Rs.Closemysql:"select sum(应收金额) as 总金额 from che where 时间>#2004-01# and 时间<#2004-02# and 车型='3' and 最大超限率<0.31"
mysql 应该没有问题, 因为 总金额每次都能算对, 但是zcc不是1就是-1,好奇怪
在Rs.Open mysql, Adodc1.ConnectionString, 3, 3前面加一句
rs.CursorLocation = adUseClient
Rs.Open mysql, Adodc1.ConnectionString, 3, 3zje = Rs!总金额 & ""
zcc = Rs.RecordCount
Rs.Close另zcc是1很正常,-1有时正常有时不正常
Rs.CursorType = adOpenStatic
Rs.Open mysql, Adodc1.ConnectionString, 3, 3zje = Rs!总金额 & ""
zcc = Rs.RecordCount
还是不行啊! zcc每次都是1
可以
rs.movefirst
在 zcc = Rs.RecordCount
正常?那我的要求怎么实现
to:haisuifeng(海随风)
zcs还是1啊!拜托大家给说个好使得方法吧!
dim str1() as string
str1=rs.GetRowsmsgbox ubound(str1) 即为你要的记录数
感谢你的提醒,可惜还是不行,拜托你下次试试好吗?这样不会有分的
我的分只给能解决问题的人!
虽然你设置了
Rs.CursorType = adOpenStatic
但是这里
Rs.Open mysql, Adodc1.ConnectionString, 3, 3
又可能改变,所以那句失效
而设置
CursorLocation = adUseClient
你设置记录集光标自动变成静态,你自定义的将被忽略,所以这时recordcount有效,如果无效返回的应该是-1
为什么老是1你就要检查你返回的记录是不是真的就是1条
Rs.Open mysql, Adodc1.ConnectionString, 3, 1然后msgbox rs.recordcount看看
====
当在服务器端请求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.
Rs.MoveLast '将指针移到尾记录.
zcc=Rs.RecordCount '取记录总数.
Rs.MoveFirst '再将指针移到首记录.