If you are building a Web Site, you can gain additional scalability and performance by placing your populated DataSet instance into the ASP.NET Cache object. This prevents redundant (and potentially slow) calls to the database to populate the DataSet. For more information, see If You Use DataSets, Cache Them.
Note If your DataSet contains standard values for all users, use the Cache object. However, if your DataSet contains unique values for each user (based on a user-specific criteria in the WHERE clause of the SQL query, such as user id) then you should use the Session object instead.
In this section, you expand one line of code that assigns the CustomerDataSet property to the DataSet instance to a complete code block that manages DataSet caching.
To modify your Web Site to check for a cached DataSet
myDataSet = DataSetConfiguration.CustomerDataSet
dataSet = DataSetConfiguration.CustomerDataSet;
Enter the conditional block and code exactly as shown here.
If Cache("customerDataSet") Is Nothing Then
myDataSet = DataSetConfiguration.CustomerDataSet
Cache("customerDataSet") = myDataSet
Else
myDataSet = CType(Cache("customerDataSet"), DataSet)
End If
if (Cache["customerDataSet"] == null)
{
dataSet = DataSetConfiguration.CustomerDataSet;
Cache["customerDataSet"] = dataSet;
}
else
{
dataSet = (DataSet)Cache["customerDataSet"];
}
You are now ready to build and run your Web Site to test the cached DataSet.
To test the caching of the DataSet
The Customer report displays and shows the populated data that you placed in the DataSet.
The Customer report displays again quickly, because the DataSet is now retrieved from the ASP.NET Cache object.
Continue to Conclusion.
Tutorial: Connecting to ADO.NET DataSets | Tutorials and Sample Code | Tutorials' Sample Code Directory