【发布时间】:2016-10-26 14:25:00
【问题描述】:
我有一个运行良好的 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 查询的所有记录。我尝试了几个论坛的几种解决方案,但没有一个适合我。
【问题讨论】:
-
INSERT语句不返回任何记录。如果要显示插入的内容,则需要将语句的SELECT部分作为单独的语句运行。如需进一步帮助,请展示您的尝试,并说明结果与您的预期有何不同。 -
我的帖子是用我测试过的代码编辑的。我发现的解决方案要求处理 RecordSet,我对此不是很强大。
-
@AnsgarWiechers 完成
-
谢谢。不要忘记接受您的回答。
标签: sql database sqlite vbscript msgbox