欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Asp.Net Cache緩存使用代碼

 更新時間:2008年12月19日 12:45:09   作者:  
本例完成建立緩存,清除緩存使用緩存進行數(shù)據(jù)綁定
復制代碼 代碼如下:

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
{
//緩存存在執(zhí)行綁定
DataSet ds=(DataSet)Cache["DataList"];
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
}
}

相關文章

最新評論