我目前正在开发一个数据库挖掘程序,以从 sqlite db 中提取数据并填充表单。这需要同时从几个不同的表中提取几种类型的数据,并且看起来已经有点资源密集型了。有没有更好的方法来解决这个问题?我应该使用后台工作人员来运行 sql 查询吗?我正在运行多个 SQLiteCommand.ExecuteReader 实例,是否可以避免这种情况?
代码:
Public Shared Sub SQLInq()
'Database Information
Dim connection As String = "Data Source=" & _Compression.path
Dim SQLConn As New SQLiteConnection(connection)
Dim SQLcmd As New SQLiteCommand(SQLConn)
Dim SQLdr As SQLiteDataReader
'Connect to Database
SQLConn.Open()
SQLcmd.Connection = SQLConn
'Run query
SQLcmd.CommandText = "Select * FROM FsFileVersion WHERE FileDescription_LTH = 'filea' LIMIT 1;"
SQLdr = SQLcmd.ExecuteReader()
While SQLdr.Read()
fileaVrsn = (SQLdr.GetString(SQLdr.GetOrdinal("FileVersion_LTH")))
End While
SQLdr.Close()
'Run query
SQLcmd.CommandText = "Select * FROM FsFileVersion WHERE FileDescription_LTH = 'fileb' LIMIT 1;"
SQLdr = SQLcmd.ExecuteReader()
While SQLdr.Read()
filebVrsn = (SQLdr.GetString(SQLdr.GetOrdinal("FileVersion_LTH")))
End While
SQLdr.Close()
'Close connection
SQLConn.Close()
'Revert cursor wait to arror
Application.Current.MainWindow.Cursor = Cursors.Arrow
End Sub