SQL 个 MsgBox 中的记录

SQL records in a MsgBox

我有一个运行良好的 VBS 程序。我的代码如下:

Dim qry, db, cs, cn, cmd

'Query to add all the following which date more than 20 days in the table ToUnfollow
qry  = "INSERT INTO ToUnfollow " & _
       "SELECT Name FROM Follow t1 " & _
       "WHERE t1.Joined < datetime(CURRENT_DATE, '-20 days') " & _
       "AND NOT EXISTS (SELECT 1 FROM ToUnfollow t2 WHERE t2.Name=t1.Name);"

db = "C:\Users\Quentin\Downloads\Quentin-Classementhashtags.db"
cs = "DRIVER=SQLite3 ODBC Driver;Database=" & db

'Connection to database
Set cn = CreateObject("ADODB.Connection")
cn.Open cs

Set cmd = CreateObject("ADODB.Command")
Set cmd.ActiveConnection = cn

'Execute the SQL query
cmd.CommandText = qry
cmd.Execute

'Close the connection
cn.Close

我想在 MsgBox 中显示来自 SQL 查询的所有记录。我尝试了几个论坛的几种解决方案,但 none 对我有用。

我的解决方案:

Dim qry, db, cs, cn, cmd, adoRec, name

'Query to add all the following which date more than 20 days in the table
'ToUnfollow
qry  = "SELECT Name, Joined FROM Follow t1 " & _
       "WHERE t1.Joined < datetime(CURRENT_DATE, '-20 days')"

db = "C:\Users\Quentin\Downloads\Quentin-Classementhashtags.db"
cs = "DRIVER=SQLite3 ODBC Driver;Database=" & db

'Connection to database
Set cn = CreateObject("ADODB.Connection")
cn.Open cs

Set cmd = CreateObject("ADODB.Command")
Set cmd.ActiveConnection = cn

cmd.CommandText = qry
Set adoRec = cmd.Execute()

'Iterate through the results
While Not adoRec.EOF
  name = name & vbCr & adoRec(0) & " - " & adoRec(1)
  adoRec.MoveNext
Wend

MsgBox name

'Close the connection
cn.Close