VB使用Sqlite3

前端之家收集整理的这篇文章主要介绍了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

---

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

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

点击到下载

原文链接:https://www.f2er.com/vb/257755.html

猜你在找的VB相关文章