Answers

Question and Answer:

  Home  ASP.NET Caching

⟩ Do you know about caching with the DataSource Controls?

The DataSource controls enable you to cache database data while connecting a .NET application to a database. The DataSource control provides various properties, such as EnableCaching, which you can use to automatically cache the data represented by a DataSource control. The syntax to cache a database table in a memory for 120 seconds is:

<asp:SqlDataSource ID=”SqlDataSource1” EnableCaching=”True” CacheDuration=”120”

ConnectionString=”Server=localhost;database=AdventureWorks;uid=user;pwd=word;”

SelectCommand=”SELECT * FROM Production.ProductCategory” Runat=”server”/>

The above syntax caches a database table, ProductCategory, by setting the EnableCaching property of the DataSource control to True. The CacheDuration property of the DataSource control specifies the time, in seconds, for caching the data before it is updated in a database containing the ProductCategory table. The value of the Time parameter is set to 120 to cache data for two minutes.

 147 views

More Questions for you: