VB使用Sqlite3

国内现在用VB好像很少了,一个项目用到sqlite3,发现相关资料比较凌乱,也有很多不同使用方法。需要注意的是,Vb调用sqlite3可使用附件里的dll,官方网站下载的不好用(注册老是失败)。特把使用方法记录在这里。

1.添加附件的类模块cCDECL.cls

2.添加附件的模块mDeclarations.bas,msqlite.bas

3.

Private Sub checkHistory()
    Dim sPath As String
    sPath = App.path & "\..\data\"
    If msqlite.sqlite3_initialize(sPath) <> sqlITE_OK Then
        Debug.Print "error"
        Exit Sub
    End If
    
    If msqlite.sqlite3_open(sPath & "data.sqlite",f_lsqlite) <> sqlITE_OK Then
        Debug.Print "error"
        Exit Sub
    End If
     
    If msqlite.sqlite3_prepare_v2(f_lsqlite,"SELECT id,flag,send_username,send_cop,send_mail,send_phone,cmbType,cmbW,cmbC,cmbH FROM history WHERE flag=0",f_lStatement,0) = sqlITE_OK Then

        Dim send_username As String,send_cop As String,send_mail As String,send_phone As String
        Dim cmbType As String,cmbW As Integer,cmbC As Integer,cmbH As Integer
        ' add lasttime
        
        Do While msqlite.sqlite3_step(f_lStatement) = sqlITE_ROW
            Debug.Print msqlite.sqlite3_column_int(f_lStatement,0)
            Debug.Print msqlite.sqlite3_column_text(f_lStatement,1)
            send_username = msqlite.sqlite3_column_text(f_lStatement,2)
            send_cop = msqlite.sqlite3_column_text(f_lStatement,3)
            send_mail = msqlite.sqlite3_column_text(f_lStatement,4)
            send_phone = msqlite.sqlite3_column_text(f_lStatement,5)
            cmbType = msqlite.sqlite3_column_text(f_lStatement,6)
            cmbW = msqlite.sqlite3_column_int(f_lStatement,7)
            cmbC = msqlite.sqlite3_column_int(f_lStatement,8)
            cmbH = msqlite.sqlite3_column_int(f_lStatement,9)
            generate send_username,cmbH
            msqlite.sqlite3_exec f_lsqlite,"UPDATE history set flag=1 WHERE id=" & msqlite.sqlite3_column_int(f_lStatement,0)
        Loop
    Else
        Debug.Print msqlite.sqlite3_errmsg(f_lsqlite)
    End If

    Call msqlite.sqlite3_finalize(f_lStatement)
    
    '// Close DB handle
    Call msqlite.sqlite3_close(f_lsqlite)
    
    '// Terminate wrapper
    Call msqlite.sqlite3_shutdown
End Sub
我的项目目录结构是:

data

---data.sqlite

vb

---

自己使用的时候要注意修改数据库路径。

--没找到上传附件的地方,放到下载资源里了。这里直接使用别人的程序,感谢原作者:

点击到下载

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强制返回为文本 --------------------------...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办法, Format 或者FormatDateTime 竟然结果和...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace My ‘全局错误处理,新的解决方案直接...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用的爽呀,这篇文章写与2011年,看来我以前没...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选中的单元格进行处理 Dim m As Range, t...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integ...