簡體   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