ASP.NET缓存依赖--SQL Server 2005与SQL Server 2008缓存依赖(3)
private SqlCacheDependency dependency;
private string connectionString =
WebConfigurationManager.ConnectionStrings
["ConnectionString"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
SqlDependency.Stop(connectionString);
SqlDependency.Start(connectionString);
lblInfo.Text += "开始创建依赖项...<br />";
Cache.Remove("employee");
DataTable dt = GetTable();
Cache.Insert("employee", dt, dependency);
lblInfo.Text += "添加依赖项:
Cache.Insert(\"employee\", dt, dependency)<br />";
}
}
private DataTable GetTable()
{
SqlConnection con =
new SqlConnection(connectionString);
using (con)
{
string sql = "select employeename from dbo.employee";
SqlDataAdapter da = new SqlDataAdapter(sql, con);
dependency =
new SqlCacheDependency(da.SelectCommand);
DataSet ds = new DataSet();
da.Fill(ds, "employee");
return ds.Tables[0];
}
相关新闻>>
- 发表评论
-
- 最新评论 更多>>