Hello,
I'm learning about VB.Net using the SQLite wrapper, and get this error message when calling SELECT while looping through a list of items. As shown, setting SQLRead=Nothing doesn't solve the run-time error:
------------------------
Const STARTDIR = "C:\MyDir\"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
ListBox1.Items.Clear()
Dim SQLconnect As New SQLite.SQLiteConnection()
Dim SQLcommand As SQLite.SQLiteCommand
Dim SQLtransaction As SQLite.SQLiteTransaction
Dim SQLreader As SQLite.SQLiteDataReader
SQLconnect.ConnectionString
= "Data Source=test.sqlite;"
SQLconnect.Open()
SQLcommand = SQLconnect.CreateCommand
Dim filelist As Collections.ObjectModel.ReadOnlyCollection(Of
String) = My.Computer.FileSystem.GetFiles(STARTDIR, FileIO.SearchOption.SearchAllSubDirectories)
Dim path As String
For Each path In filelist
'displayed
twice
ListBox1.Items.Add("before
error")
ListBox1.Refresh()
SQLcommand.CommandText
= "SELECT id,hash FROM files WHERE hash='@hash'"
SQLcommand.Parameters.AddWithValue("@hash",
"123456")
'DataReader
already active on this command
SQLreader
= SQLcommand.ExecuteReader()
If
Not SQLreader.HasRows Then
ListBox1.Items.Add("no
row")
Else
'Just
ignore results
SQLreader
= Nothing
End
If
Next
End Sub
------------------------
Does someone know the cause/solution of this error?
Thank you.
PS : I had to copy/paste code from VB.Net Express to a WYSIWYG HTML editor to this forum. Does someone know how to post code so it's not turned into one-line garbage?