Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How do I determine the number of records in a SQL table and then save that value in variable?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
400 views
Welcome To Ask or Share your Answers For Others

1 Answer

Using ADO to access the db:

  1. execute a simple SELECT count(0) FROM myTable query.
  2. access the resultset (if not empty) and read the returned value.

Not tested code:

Dim conn, rs, recordsCount
recordsCount = -1

'initialize the connection
set conn = ...

'run the query and retrieve the results
set rs = conn.execute("SELECT count(0) as cnt FROM myTable")
if not rs.EOF then
  recordsCount = cint(rs("cnt"))
end if


'cleanup
rs.close
conn.close

set rs = nothing
set conn = nothing

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...