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");
        }
    }

  • 相关阅读:
    介绍Shiro Annotation及Shiro标签的用法
    SpringMVC+Apache Shiro+JPA(hibernate)案例教学(四)基于Shiro验证用户权限,且给用户授权
    SpringMVC+Apache Shiro+JPA(hibernate)案例教学(一)整合配置
    Spring MVC之@RequestMapping 详解
    vimrc
    sk_buff深度解析
    ieee80211ax简介
    新基地
    dos格式迭代转为unix
    ath10k MAC地址
  • 原文地址:https://www.cnblogs.com/handboy/p/7141581.html
Copyright © 2011-2022 走看看