Help with SQLite database and VBScript

本文介绍了如何将SQLite数据库管理系统与VBScript结合使用的方法。通过使用SQLite ODBC驱动程序,可以轻松实现SQLite与VBScript之间的连接,使得SQLite成为一个轻量级且易于部署的数据库解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Hi JuanPadre, 

While MySQL is a very good DBMS, SQLite has its merits too: If you don't need a Server 
(and a Server Admin and an Assistant of the Server Admin, ...) and want 'one file deployment' 
of databases (like Acess .mdbs) or 'minimal impact of installation' (1 exe, 1 dll, 1 odbc driver), 
then SQLite is a very good solution. 

If it fits your need, don't be afraid "that SQLite is not built to easily connect to with VBScript". 
The ODBC driver 
     http://www.ch-werner.de/sqliteodbc/ 
     http://www.ch-werner.de/sqliteodbc/html/index.html 
makes the use of SQLite just as easy as any other DBMS suitable for ADO. 

To put some code behind my statement: 

 

Dim oCS     : oCS       = "Driver={SQLite3 ODBC Driver};Database=@FSPEC@;StepAPI=;Timeout="
   
Dim oCNCT   : Set oCNCT = CreateObject( "ADODB.Connection" )
 
    oCS
= Replace( oCS, "@FSPEC@", sCurDir + sFina )
    oCNCT
.Open oCS
   
WScript.Echo "connected to", sFina
 
   
Dim sSQL, oRS, nRec, oFld
 
    sSQL
= "DROP TABLE tblEasy"
   
On Error Resume Next
    oCNCT
.Execute sSQL
   
If 0 <> Err.Number Then WScript.Echo "'" + sSQL + "' failed; ok if first time"
   
On Error GoTo 0
 
    sSQL
= Array(   "CREATE TABLE tblEasy ("     _
                 
, "   ID INTEGER PRIMARY KEY"  _
                 
, " , NAME VARCHAR( 40 )"      _
                 
, ")"                          _
               
)
    sSQL
= Join( sSQL, " " )
    oCNCT
.Execute sSQL
   
WScript.Echo "table tblEasy created"
 
   
For nRec = 1 To nMxRec
        sSQL
= "INSERT INTO tblEasy VALUES( " & nRec & ", 'Name" & nRec & "' )"
        oCNCT
.Execute sSQL
   
Next
   
WScript.Echo nMxRec, "records added (in an ineffient way)"
 
    sSQL    
= "SELECT * FROM tblEasy"
   
Set oRS = oCNCT.Execute( sSQL )
   
For nRec = 1 To (nMxRec / 10 ) + 1
       
WScript.Echo "----------", nRec
       
For Each oFld In oRS.Fields
           
WScript.Echo oFld.Name, oFld.Value
       
Next
        oRS
.MoveNext
   
Next
 
    oCNCT
.Close
   
Set oCNCT = Nothing

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值