In my function I'm binding the list box:
Protected WithEvents lstMedia As System.Web.UI.WebControls.ListBox
to the dataReader.
I put the dataReader into the cache.
First time I bind the listBox is everything OK, but all the other times, when I read from the cache, the listBox is empty.
Why? Looks like that Cache object is empty.
Dim mediaRdr As SqlDataReader
mediaRdr = Cache("Mediji")
If mediaRdr Is Nothing Then
Dim sql As String
sql = "SELECT med_id,med_name FROM cpoMedium ORDER BY med_name"
mediaRdr = funkcije.createDataReader(sql, True)
Cache.Insert("Mediji", mediaRdr, New CacheDependency(MapPath("test.txt")))
End If
lstMedia.DataSource() = mediaRdr
lstMedia.DataValueField = "med_id"
lstMedia.DataTextField = "med_name"
lstMedia.DataBind()
By the way, can I cache all listBox, instead of caching the datareader?
Thank you for your answer,
Simon
FRED \( from BRASIL - SP \) - 24 Mar 2004 11:05 GMT
Hi Simon,
your problem is the datareader. You only can read one time, then he will be empty.
This is the standard with datareader.
For caching data see this article(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cp
conaddingitemstocache.asp).
Bye,
Fred (from Brasil)
In my function I'm binding the list box:
Protected WithEvents lstMedia As System.Web.UI.WebControls.ListBox
to the dataReader.
I put the dataReader into the cache.
First time I bind the listBox is everything OK, but all the other times, when I read from the cache, the listBox is empty.
Why? Looks like that Cache object is empty.
Dim mediaRdr As SqlDataReader
mediaRdr = Cache("Mediji")
If mediaRdr Is Nothing Then
Dim sql As String
sql = "SELECT med_id,med_name FROM cpoMedium ORDER BY med_name"
mediaRdr = funkcije.createDataReader(sql, True)
Cache.Insert("Mediji", mediaRdr, New CacheDependency(MapPath("test.txt")))
End If
lstMedia.DataSource() = mediaRdr
lstMedia.DataValueField = "med_id"
lstMedia.DataTextField = "med_name"
lstMedia.DataBind()
By the way, can I cache all listBox, instead of caching the datareader?
Thank you for your answer,
Simon
Scott M. - 24 Mar 2004 19:39 GMT
DataReaders represent a forward-only, read-only "firehose type cursor".
They can only be iterated through from beginning to end one time.
Use a DataTable and/or DataSet instead.
In my function I'm binding the list box:
Protected WithEvents lstMedia As System.Web.UI.WebControls.ListBox
to the dataReader.
I put the dataReader into the cache.
First time I bind the listBox is everything OK, but all the other times,
when I read from the cache, the listBox is empty.
Why? Looks like that Cache object is empty.
Dim mediaRdr As SqlDataReader
mediaRdr = Cache("Mediji")
If mediaRdr Is Nothing Then
Dim sql As String
sql = "SELECT med_id,med_name FROM cpoMedium ORDER BY med_name"
mediaRdr = funkcije.createDataReader(sql, True)
Cache.Insert("Mediji", mediaRdr, New
CacheDependency(MapPath("test.txt")))
End If
lstMedia.DataSource() = mediaRdr
lstMedia.DataValueField = "med_id"
lstMedia.DataTextField = "med_name"
lstMedia.DataBind()
By the way, can I cache all listBox, instead of caching the datareader?
Thank you for your answer,
Simon