Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Caching / March 2004

Tip: Looking for answers? Try searching our database.

Caching the dataReader

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
simon - 23 Mar 2004 14:47 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.