zoukankan      html  css  js  c++  java
  • ADO:DataSet存入缓存Cache中并使用

    原文发布时间为:2008-08-01 —— 来源于本人的百度文章 [由搬家工具导入]

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    using System.Data.SqlClient;

    public partial class Cacheds : System.Web.UI.Page
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {
            DataSet ds=(DataSet)Cache.Get("ds_cache");
            if (!IsPostBack)
            {
                if (ds == null)
                {
                    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["pubsConn"].ConnectionString);
                    SqlDataAdapter sda = new SqlDataAdapter();
                    sda.SelectCommand = new SqlCommand("select title_id,title,type from titles", conn);
                    DataSet cds = new DataSet();
                    sda.Fill(cds, "t1");

                    cds.ExtendedProperties.Add("ds_t1", DateTime.Now.ToLongTimeString());
                    Cache.Insert("ds_cache", cds, null, DateTime.Now.AddMinutes(2), TimeSpan.Zero);

                    Response.Write("对象已经从数据库填充并存入Cache");
                    GridView1.DataSource = cds.Tables["t1"];
                    GridView1.DataBind();
                }

                else
                {
                    Response.Write("对象还在缓存Cache中,直接调用");
                    GridView1.DataSource = ds.Tables["t1"];
                    GridView1.DataBind();
                }
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Cache.Remove("ds_cache");
        }
    }

  • 相关阅读:
    李开复:聪明人创业为何仍容易失败?
    七种公司永远做不大,十种老板永远不成功
    最优秀的创意来自留白
    七个图表解读VC们在种子轮融资的影响
    11款可以优化网站着陆页的工具
    O2O“世界大战”:美团全线开战,点评合纵连横
    初创企业网站如何在3天内获得10万浏览量
    “感谢”——新的意志力
    主动倾听的三个秘诀
    携程事件后,云运维的安全命题何解?
  • 原文地址:https://www.cnblogs.com/handboy/p/7141581.html
Copyright © 2011-2022 走看看