Using ADODB to Query SQLite in VBScript


Querying SQLite Database via VBScript can be done via the ADODB.Connection Object. We use the Open to specify the connection String, and the Execute method to run a SQL command which should return a record set. Then we can use the MoveNext to walk through the records.

Option Explicit
Dim conn, shell

Set conn = CreateObject( "ADODB.Connection" )
Set shell = CreateObject( "WScript.Shell" )

Dim folder
folder = shell.ExpandEnvironmentStrings("%LOCALAPPDATA%")
conn.Open "Driver={SQLite3 ODBC Driver};Database=" & folder & "test.db;"

Dim rs
Set rs = conn.Execute("select * from user")
Do While Not(rs.EOF)
  WScript.Echo rs("email").Value
  rs.MoveNext
Loop

rs.Close
conn.Close

–EOF (The Ultimate Computing & Technology Blog) —

161 words
Last Post: Teaching Kids Programming - Sum of Three Numbers Less than Target
Next Post: Teaching Kids Programming - Leaf Similar Trees by Recursive Depth First Search Algorithm

The Permanent URL is: Using ADODB to Query SQLite in VBScript (AMP Version)

Leave a Reply