Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 中继器和缓存数据集出现奇怪问题-仅显示最后一行_Asp.net_Vb.net_Caching_Dataset_Repeater - Fatal编程技术网

Asp.net 中继器和缓存数据集出现奇怪问题-仅显示最后一行

Asp.net 中继器和缓存数据集出现奇怪问题-仅显示最后一行,asp.net,vb.net,caching,dataset,repeater,Asp.net,Vb.net,Caching,Dataset,Repeater,我有一段相对简单的代码,如下所示: 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)

我有一段相对简单的代码,如下所示:

        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”是一个
中继器
,方法通过存储过程从数据库读取数据集。此数据集有6个不同的表。从数据库读取数据集时,
中继器
显示36行,这是预期的结果。从缓存中读取时,它只显示一行,即最后一行。奇怪的是,当我调试时,我在这两种情况下都看到
oSearchResults.Rows.Count=36


有人知道为什么会发生这种情况吗?

要真正了解它是否与缓存有关,请尝试始终使用缓存中的数据集。在检查它是否在缓存中时,而不是去获取数据集然后使用它,去获取它,将它放入缓存中,然后使用它

因此,不是这样:

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
这样做:

If IsNothing(Cache(cacheKey)) Then
    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

oShow = DirectCast(Cache(cacheKey), DataSet)

这不会“解决”您的问题,但会缩小isue的范围。如果总是得到一行,那么就知道这与将数据集从缓存中拉出有关。如果非要我猜的话,我会说在你的代码片段之外还有其他事情发生。

我发现了问题所在。我在ItemDataBound事件中这样做:

Dim dvRows As DataView = oSearchResults.DefaultView
dvRows.RowFilter = String.Format("Submission_id={0} AND speaker_id Is Not Null", oRow("Submission_id"))
一旦我把它改成:

Dim dvRows As DataView = oSearchResults.Copy().DefaultView

问题消失了。我想知道为什么这只是缓存时的一个问题。

即使使用您的代码,所有内容都会在第一次显示,但不会在第一次之后显示。但是如果我完全删除缓存,每次都会显示所有内容。你能提供中继器的代码吗?