中继器和缓存数据集的奇怪问题 - 仅显示最后一行
我有一段相对简单的代码,如下所示:
Dim oShow As DataSet = Nothing
Dim cacheKey As String = String.Format("AsyncCacheFor_agenda_{0}", ShowID)
If Not IsNothing(Cache(cacheKey)) Then
oShow = DirectCast(Cache(cacheKey), DataSet)
Else
oShow = DataServers.dsTMW.GetAgenda(ShowID, 0, "", 0, True)
Cache.Insert(cacheKey, oShow, Nothing, System.Web.Caching.Cache.NoAbsoluteExpiration, New TimeSpan(1, 0, 0))
End If
phSearch.Visible = True
oShowRow = oShow.Tables(0).Rows(0)
oTracks = oShow.Tables(1)
oSearchResults = oShow.Tables(5)
If Not IsNothing(oSearchResults) AndAlso oSearchResults.Rows.Count > 0 Then
rptSearch.Visible = True
phNoResults.Visible = False
rptSearch.DataSource = oSearchResults
rptSearch.DataBind()
Else
rptSearch.Visible = False
phNoResults.Visible = True
End If
“rptSearch”是一个Repeater,而GetAgenda()
方法通过存储过程从数据库读取数据集。该数据集有 6 个不同的表。从数据库读取数据集时,Repeater
显示 36 行,这是预期的结果。从缓存中读取时,它仅显示一行,即最后一行。奇怪的是,当我调试时,我在两种情况下都看到oSearchResults.Rows.Count = 36
。
有谁知道为什么会发生这种情况?
I have a relatively simple piece of code as follows:
Dim oShow As DataSet = Nothing
Dim cacheKey As String = String.Format("AsyncCacheFor_agenda_{0}", ShowID)
If Not IsNothing(Cache(cacheKey)) Then
oShow = DirectCast(Cache(cacheKey), DataSet)
Else
oShow = DataServers.dsTMW.GetAgenda(ShowID, 0, "", 0, True)
Cache.Insert(cacheKey, oShow, Nothing, System.Web.Caching.Cache.NoAbsoluteExpiration, New TimeSpan(1, 0, 0))
End If
phSearch.Visible = True
oShowRow = oShow.Tables(0).Rows(0)
oTracks = oShow.Tables(1)
oSearchResults = oShow.Tables(5)
If Not IsNothing(oSearchResults) AndAlso oSearchResults.Rows.Count > 0 Then
rptSearch.Visible = True
phNoResults.Visible = False
rptSearch.DataSource = oSearchResults
rptSearch.DataBind()
Else
rptSearch.Visible = False
phNoResults.Visible = True
End If
"rptSearch" is a Repeater
and the GetAgenda()
method reads a dataset from the database via stored procedure. This dataset has 6 different tables. When the dataset is read from the database, the Repeater
displays 36 rows, the expected result. When it's read from the cache it only displays one row, the last one. What's strange is that when I debug, I see that oSearchResults.Rows.Count = 36
in both cases.
Does anyone have any idea why this might happen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要真正了解它是否与缓存有关,请尝试始终使用缓存中的数据集。在检查它是否在缓存中时,不要获取数据集然后使用它,而是获取它,将其放入缓存中,然后使用它。
因此,不要这样做:
这样做:
这不会“解决”您的问题,但会缩小问题范围。如果你总是得到 1 行,那么你就知道这与将数据集从缓存中拉出有关。如果我不得不猜测,我会说在您的代码片段之外还发生了其他事情。
To truly see if it has anything to do with the cache, try always using the Dataset from the cache. On the check to see if it is in the cache, rather than going and getting the Dataset and then using it, go get it, put it in the cache, then use it.
So, rather than this:
Do this:
This won't "fix" your issue, but it will narrow down the isue. If you get 1 row always, then you know it has to do with pulling the Dataset out of the cache. If I had to guess though, I'd say that there is something else going on outside of your code snippet.
我发现了问题所在。我在 ItemDataBound 事件中执行此操作:
一旦我将其更改为:
问题就消失了。我想知道为什么这只是缓存时的问题。
I figured out the problem. I was doing this in the ItemDataBound event:
Once I changed that to:
The problem went away. I wonder why this was only a problem when it was being cached.