国内现在用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", 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, send_cop, send_mail, send_phone, cmbType, cmbW, cmbC, 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
---
自己使用的时候要注意修改数据库路径。
--没找到上传附件的地方,放到下载资源里了。这里直接使用别人的程序,感谢原作者:
点击到下载页