|
-
Sep 22nd, 2005, 07:37 PM
#1
Thread Starter
Addicted Member
Garbage Collection Not working!
I found this out while trying to figure something out.
When you try to use a data reader in a function:
Function LoadtoList()
Dim myLoad As New OleDbCommand("Select * from Questions order by Num",mycon)
dim rd as system.Data.OleDb.OleDbDataReader
myload.CommandType = myLoad.CommandType.Text
rd = myload.ExecuteReader()
lvqs.Items.clear()
While rd.Read()
Dim x As new ListViewItem
x.Text = rd.GetValue(0).ToString()
x.SubItems.add(rd.GetValue(1).ToString())
x.SubItems.add(rd.GetValue(2).ToString())
x.SubItems.add(rd.GetValue(3).ToString())
x.SubItems.add(rd.GetValue(4).ToString())
x.SubItems.add(rd.GetValue(6).ToString())
lvqs.Items.add(x)
End While
End Function
In here, when the function ended, the rd object must have been disposed because the the variable life cycle is just within the function. But it will not! try using any commands that will execute on the database and you will get an error that you there is an opened data reader.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|