易截截图软件、单文件、免安装、纯绿色、仅160KB

ASP.NET页面传值_第九篇_Cache

+++ PassDatatableByCache01.aspx页面
++ 页台代码如下:
<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="用Cache传数据集"></asp:Button>
++ 后台代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
  string connStr = "Data Source=ora11g;uid=scott;pwd=tiger;unicode=true";
  string sqlStr = "SELECT * from EMP";
  OracleDataAdapter da = new OracleDataAdapter(sqlStr, connStr);
  DataTable dt = new DataTable();
  da.Fill(dt);
  Cache.Insert("statistic", dt,
      null,
      DateTime.Now.AddMinutes(10), Cache.NoSlidingExpiration);
  Response.Redirect("PassDatatableByCache02.aspx");
}
+++ PassDatatableByCache02.aspx页面
++ 页面代码如下:
(略)
++ 后台代码如下:
protected void Page_Load(object sender, EventArgs e)
{
  if (Cache.Get("statistic") != null)
  {
    DataTable dt = (DataTable)Cache.Get("statistic");
    foreach (DataRow dr in dt.Rows)
    {
        Response.Write(dr[0].ToString() + "</br>");
    }
  }
  else
  {
    Response.Write("Cache缓存中没有内容!");
  }
}
+++ 说明
(1) 本例用Cache传递数据集;
(2) 用Cache传递数据集要比Session可行得多,Cache使用更灵活,而且可以设置过期时间或是缓存依赖;
(3) 在本BLOG的Cache分类中有Cache的详尽使用。


相关文档:

ASP.NET 定时执行一段代码 Global.asax

在Global.asax启动一条线程就ok了,下面是启动线程定时写文件的例子
在Global.asax
C# code:
<%@ Application Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Threading" %>
<script runat="server">   
 string LogPath;  ......

asp.net页面事件执行顺序及各事件作用

    protected void Page_Load(object sender, EventArgs e)
    {
    }
    #region OnPreInit 第一步
    protected override void OnPreInit(EventArgs e)
    {
        //检查 ......

ASP.NET页面传值_第五篇_Application

+++ 修改Global.asax文件:
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
  Application["count"] = 0;
}
void Application_End(object sender, EventArgs e)
{  }
void Application_Error(object sender, EventArgs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号