Ejemplo n.º 1
0
 private void GetDataFromCache()
 {
     if (Cache["DATASET"] != null)
     {
         DataSet ds = (DataSet)Cache["DATASET"];
         Gvw_Students.DataSource = ds;
         Gvw_Students.DataBind();
     }
 }
Ejemplo n.º 2
0
        private void GetDataFromDb()
        {
            string         connectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
            SqlConnection  con            = new SqlConnection(connectionString);
            string         strSelectQuery = "SELECT * FROM Students";
            SqlDataAdapter da             = new SqlDataAdapter(strSelectQuery, connectionString);

            DataSet ds = new DataSet();

            da.Fill(ds, "Students");

            ds.Tables["Students"].PrimaryKey = new DataColumn[] { ds.Tables["Students"].Columns["Id"] };
            Cache.Insert("DATASET", ds, null, DateTime.Now.AddHours(24), System.Web.Caching.Cache.NoSlidingExpiration);

            Gvw_Students.DataSource = ds;
            Gvw_Students.DataBind();

            Lbl_Message.Text = "Data Loaded from Database";
        }