locked
May I get the number of records previously retrieved from a sqlDataSource cache RRS feed

  • Question

  • User426001450 posted

    I do have a sqlDataSource with the following properties:

    EnableCaching="true" CacheDuration="600"  

    When the page is requested for the first time, the server cache the data source information for 10 minutes (CacheDuration="600"). The sqlDataSource won’t execute again before cache expired even though a user request this page again. All relate info to display this page is going to be retrieve from Cache instead. Since this is the case, how could I access cache to find the number of records that the sqlDataSource retrieved when it first executed. Is there any way to access this value in memory? Where is this value? Does the server only cache the page as a picture and drop all values? Please explain, thanks.    

    Saturday, December 29, 2018 3:10 PM

Answers

  • User426001450 posted

    Ok guys, this is the best way to do it. I found that the best way to do it is to work with the ListView instead of the sqlDataSource. I just call the ListView row count property from code behind. Here is the code.

    Protected Sub XListView_DataBound(sender As Object, e As EventArgs)
            comment1 = "Your search returned "
            comment2 = " record(s)."
            rowResult = XListView.Items.Count.ToString
            DisplayRowResult.Text = (comment1 + rowResult + comment2).ToString
    End Sub


       

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 30, 2018 1:54 AM

All replies

  • User475983607 posted

    I do have a sqlDataSource with the following properties:

    EnableCaching="true" CacheDuration="600"  

    When the page is requested for the first time, the server cache the data source information for 10 minutes (CacheDuration="600"). The sqlDataSource won’t execute again before cache expired even though a user request this page again. All relate info to display this page is going to be retrieve from Cache instead. Since this is the case, how could I access cache to find the number of records that the sqlDataSource retrieved when it first executed. Is there any way to access this value in memory? Where is this value? Does the server only cache the page as a picture and drop all values? Please explain, thanks.    

    You can get the number of records from any request (any page life cycle event handler) directly by invoking the select method of the SqlDataSource.

    https://forums.asp.net/t/1501796.aspx?retrieveing+record+count+from+SQLDataSource+Control

    Be sure you read the SqlDataSource.EnableCaching docs so you understand the SqlDataSource is coming from cache.  It is up to you to invoke the fetch depending on what you're doing.  Keep in mind it is always best to share your code when asking for assistance.

    Saturday, December 29, 2018 3:23 PM
  • User426001450 posted

    mgebhard

    You can get the number of records from any request (any page life cycle event handler) directly by invoking the select method of the SqlDataSource.

    https://forums.asp.net/t/1501796.aspx?retrieveing+record+count+from+SQLDataSource+Control

    Be sure you read the SqlDataSource.EnableCaching docs so you understand the SqlDataSource is coming from cache.  It is up to you to invoke the fetch depending on what you're doing.  

    Ok, but when the sqlDataSource cache and another user retrive the page, the sqlDataSource does not execute. This is done on purpose by the server in order to save time and for better performance. The is the purpose of cache. Since it does not execute it is not possible to invoke the select method when requesting the page for second time after cache.

    Saturday, December 29, 2018 3:55 PM
  • User475983607 posted
    Your are explaining how cache works. Getting the count is very simple and explained in the link. If you are trying to solve a different problem, you'll need to explain the problem clearly.
    Saturday, December 29, 2018 4:29 PM
  • User426001450 posted

    This is from the link:

    protected void Page_Load(object sender, EventArgs e)
        {       
                System.Data.DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
                Label1.Text = dv.Count.ToString();
        }

    I do have ListView instead of DataView. Seen to be that this can not be done for ListView. I'm coding in VB as well. How can I do something similar for ListView?

    Saturday, December 29, 2018 9:01 PM
  • User426001450 posted

    Ok guys, this is the best way to do it. I found that the best way to do it is to work with the ListView instead of the sqlDataSource. I just call the ListView row count property from code behind. Here is the code.

    Protected Sub XListView_DataBound(sender As Object, e As EventArgs)
            comment1 = "Your search returned "
            comment2 = " record(s)."
            rowResult = XListView.Items.Count.ToString
            DisplayRowResult.Text = (comment1 + rowResult + comment2).ToString
    End Sub


       

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 30, 2018 1:54 AM