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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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) —

GD Star Rating
loading...
178 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

Leave a Reply