What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 9398 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > ASP.NET > How to add a Dataset in to a Data Cache? ...
Vpramodg

How to add a Dataset in to a Data Cache?

 Code Snippet posted by: Vpramodg | Posted on: 10/18/2010 | Category: ASP.NET Codes | Views: 1850 | Status: [Member] | Points: 40 | Alert Moderator   


Caching is a method used to increase the performance by keeping the frequently accessed data in memory.

Here is the example for Data Caching

using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class DataCaching : System.Web.UI.Page
{
SqlConnection objCon = new SqlConnection();
SqlCommand objCmd = new SqlCommand();
SqlDataAdapter objAda = new SqlDataAdapter();
DataSet objDs = new DataSet();
DataView objview;


protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
objview = (DataView)Cache["testCache"];
if (objview == null)
{
objCon.ConnectionString = "Data Source=.;Initial Catalog=Company;Integrated Security=True;";
objCmd.Connection = objCon;
objCmd.CommandText = "select * from emp";
objAda.SelectCommand = objCmd;
objAda.Fill(objDs, "emp");
objview = new DataView(objDs.Tables["emp"]);
Cache["testCache"] = objview;
lblData.Text = "Dataset from Table:";

}
else
{
lblData.Text = "Dataset from Cache:";

}
GridView1.DataSource = objview;
GridView1.DataBind();
}
}
}

Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/25/2013 7:17:48 PM