I have this code:
For some reason, the Cache is not expiring. What is wrong with this code? I am aware that I could do this using the SqlDataSource1.SqlCacheDependency property, but I'd like to know how to do it using the SqlCacheDependency object. Could someone tell me why this code is not working?Code:protected void Button3_Click(object sender, EventArgs e) { DataView dv2 = (System.Data.DataView)Cache["SqlSource"]; if (dv2 == null) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["SampleDBConnectionString"].ConnectionString); SqlCommand cmd = new SqlCommand("Select id, product, warehouse, quantity from inventory", con); SqlCacheDependency sqlDep = new SqlCacheDependency(cmd); SqlDataSource1.SelectCommand = "Select id, product, warehouse, quantity from inventory"; dv2 = (System.Data.DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty); Cache.Insert("SqlSource", dv2, sqlDep, System.Web.Caching.Cache.NoAbsoluteExpiration,new TimeSpan(0, 0, 0, 5)); } int x = dv2.Table.Rows.Count; Label2.Text = x.ToString(); }




Reply With Quote