default.aspx.cs
来自「水晶报表详细资料水晶报表详细资料水晶报表详细资料」· CS 代码 · 共 92 行
CS
92 行
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.Web.Caching;
using System.Data.SqlClient;
using System.Xml;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DisplayCacheInfo()
{
string cacheCount = Cache.Count.ToString();
this.Label1.Text = "共包括"+cacheCount+"个缓存对象:";
IDictionaryEnumerator cacheEnum = Cache.GetEnumerator();
while (cacheEnum.MoveNext())
{
this.Label1.Text+= cacheEnum.Key.ToString();
}
}
//添加按钮,用于将数据信息保存在缓存中
protected void Button3_Click(object sender, EventArgs e)
{
//将数据信息添加到缓存中
SqlConnection conn = new SqlConnection("Server=a\\mr;uid=sa;pwd=;database=db_21");
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from tb_StuInfo", conn);
DataSet ds = new DataSet();
da.Fill(ds, "student");
if (Cache["key"] == null)
{
Cache.Insert("key", ds);
}
this.Label2.Text = "";
DisplayCacheInfo();
}
//检索按钮,用于从缓存中检索指定的数据信息是否存在
protected void Button2_Click(object sender, EventArgs e)
{
if (Cache["key"] != null)
{
this.Label2.Text = "已检索到缓存中包括该数据!";
this.GridView1.DataSource = (DataSet)Cache["key"];
this.GridView1.DataBind();
}
else
{
this.Label2.Text = "未检索到缓存中包括该数据!";
this.GridView1.DataSource = null;
this.GridView1.DataBind();
}
DisplayCacheInfo();
}
//移除按钮,用于从缓存中移除指定的数据信息
protected void Button1_Click(object sender, EventArgs e)
{
if (Cache["key"] == null)
{
this.Label2.Text = "未缓存该数据,无法删除!";
}
else
{
Cache.Remove("key");
this.Label2.Text = "删除成功!";
}
if (Cache["key"] == null)
{
this.GridView1.DataSource = null;
this.GridView1.DataBind();
}
DisplayCacheInfo();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?