注册 登录
编程论坛 SQLite论坛

sqlite3内存数据库可以多次连接吗?

pz570813 发布于 2020-04-17 17:29, 2198 次点击
我先创建了一个守护进程,然后打开一个sqlite3的内存数据库。
请问接下来如何连接、读写这个内存数据库?
2 回复
#2
厨师王德榜2020-04-20 09:08
代码为例,其它语言大同小异,可自行参考:
程序代码:
dim DbFullName as string = "c:\userdb.db"
Dim qstr1 As String = "SELECT c3 ,c5 , c2 ,c4 ,c1 FROM tab1;"
dim DbConn As SQLiteConnection
Dim ConnStrBuilder As New SQLiteConnectionStringBuilder With { .DataSource = DbFullName}  
DbConn = New SQLiteConnection With {.ConnectionString = ConnStrBuilder.ConnectionString}
Try
   
            DbConn.Open()  '连接
   
            Dadapter = New SQLiteDataAdapter(qstr1, DbConn)

            Dadapter.Fill(Dset, "tab1")  
'读取
    ' 如果要更新,把Dadapter.UpdateCommand改为Update ... 语句.(表最好设置主键) 再:
   
'Dadapter.Update(Dset.Tables("tab1"))
        
            Me.DGVLocalDb1.DataSource = Nothing
            Me.DGVLocalDb1.DataSource = Dset.Tables("tab1")

            Me.ToolStripStatusLabel1.Text = "提示:读入配置文件...成功。"

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
#3
pz5708132020-04-22 22:01
非常感谢!
1