繁体   English   中英

ADODB-如何仅获取记录总数

[英]ADODB - how to get only the total number of records

仅获得记录总数的最佳方法是什么?

Dim oRS as new ADODB.Recordset
dim recordCount as Long

oRS.Open "Select * FROM [tablename]", myConnection, adOpenStatic, adLockReadOnly
If Not oRS.EOF Then recordCount = oRS.RecordCount

关键是adOpenStatic 它允许.RecordCount获取记录集中记录的实际计数。

当然,如果您需要的只是一个表中有多少条记录:

Dim oRS as new ADODB.Recordset
dim recordCount as Long

oRS.Open "Select Count(*) FROM [tablename]", myConnection, adOpenForwardOnly, adLockReadOnly
If Not oRS.EOF Then recordCount = oRS(0).Value

尝试这些解决方案之一。

SELECT * FROM <tablename>

With rs
  .CursorType = 3
  .CursorLocation = 3
  .Open sql, RecEngine  
  MsgBox .RecordCount & " records"
End With

假定已经打开的连接(在QTP / UFT中完成):

Set RecEngine = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.recordset")
RecEngine.Open <connectionString>
set rs = RecEngine.Execute("SELECT count(*) FROM <tablename>")
MsgBox rs(0)

或使用相同的开放连接:

If rs.Supports(adApproxPosition) = TRUE Then
  i = rs.RecordCount
  MsgBox i  
  'MsgBox rs.Fields(0).Value & " records"  'If doing select * rather than select count(*)   
End If

ADOQuery,SQL =“从mytable的xyz中选择count(*)”?

rs.RecordCount?

i = 0
while not rs.eof
  i = i + 1
  rs.next?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM