加入收藏 | 设为首页 | 会员中心 | 我要投稿 焦作站长网 (https://www.0391zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

Asp.Net Cache缓存使用代码

发布时间:2020-03-14 22:29:12 所属栏目:Asp教程 来源:站长网
导读:本例完成建立缓存,清除缓存使用缓存进行数据绑定


public DataSet createCache()
{
//返回DataSet
DataSet ds=new DataSet();
OleDbConnection conn=new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source="+Server.MapPath("data.mdb"));
conn.Open();
string sql="select * from data1 order by createtime asc";
OleDbDataAdapter cmd=new OleDbDataAdapter(sql,conn);
cmd.Fill(ds);
cmd.Dispose();
conn.Dispose();
return ds;
}

private void Button1_Click(object sender, System.EventArgs e)
{
//清除Cache
Cache.Remove("DataList");
Response.Write("缓存清除成功");
}

private void Button2_Click(object sender, System.EventArgs e)
{
//建立Cache
if(Cache["DataList"]==null)
{
//缓存不存在建立缓存
Cache.Insert("DataList",(DataSet)createCache());
DataSet ds=(DataSet)Cache["DataList"];
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
}
else
{
//缓存存在执行绑定
DataSet ds=(DataSet)Cache["DataList"];
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
}
}

(编辑:焦作站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读