示例#1
0
 private void GetDataFromCache()
 {
     if (Cache["DATASET"] != null)
     {
         DataSet ds = (DataSet)Cache["DATASET"];
         Gvw_Students.DataSource = ds;
         Gvw_Students.DataBind();
     }
 }
示例#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";
        }