复制代码 代码如下:
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();
}
}
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!