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.Data.SqlClient;
using System.Web.Caching;

public partial class test_cache_sql_2005_2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
		DataSet ds;
		if (Cache["ds2"] == null)
		{
			string cs = ConfigurationManager.ConnectionStrings["bancaConnectionString"].ConnectionString;
			SqlConnection cx = new SqlConnection(cs);
			SqlDataAdapter da = new SqlDataAdapter("select id_agence,nom_agence from dbo.agence", cx);

			// active la réception de notifications
			da.SelectCommand.NotificationAutoEnlist = true;

			System.Web.Caching.SqlCacheDependency dep=dep = new SqlCacheDependency(da.SelectCommand);			
			
			ds = new DataSet();
			da.Fill(ds);
			Cache.Insert("ds2", ds, dep);

			Label1.Text = "Rechargement des données à " + DateTime.Now.ToLongTimeString();
		}
		else
			ds = (DataSet)Cache["ds2"];

		GridView1.DataSource = ds;
		GridView1.DataBind();
    }
}
