Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Caching Gridview Problem

Author  Topic 

OBINNA_EKE
Posting Yak Master

234 Posts

Posted - 2006-11-14 : 04:43:06
Sometimes the caches works most time it won't work.
What are my doing wrong ?
Any reason pls people?


private void BindGrid()
{
DataView Source;
DataView dv = null;
Source = (DataView)Cache["MyDataSet"];
DataSet ds = new DataSet();
if (Source == null)
{
myDate = DateTime.Now.ToString();
Session["myDate"] = myDate;
Cache["SqlPubsEmployees"] = "SomeValue";
string[] keys = new String[1];
keys[0] = "SqlPubsEmployees";
SqlConnection MySqlConn = new SqlConnection("Data Source=SQL01;Initial Catalog=CustomerSupport;User ID=CSupportUser;Password=CSupportUserpw");
SqlDataAdapter da = new SqlDataAdapter("SELECT * from qViewAllCalls", MySqlConn);
da.Fill(ds, "Authors");
Source = new DataView(ds.Tables["Authors"]);
dv = Source;
CacheDependency MyDependency = new CacheDependency(null, keys);
Cache.Insert("MyDataSet", dv, MyDependency);
//Cache.Insert("MyDataSet", dv,null,DateTime.Now.AddDays(5),TimeSpan.Zero);
//Cache.Insert("MyDataSet", dv,MyDependency, DateTime.Now.AddHours(24), TimeSpan.Zero);

CacheStatus.Text = "New Version Created on <b>" + myDate + "</b>";
MySqlConn.Close();
}
else
{
CacheStatus.Text = " <font color='red'>Dataset retrieved from cachex <b>" + GetLastCached() + "</b> </font>";
}

if (ViewState["sortexpression"] != null)
{
dv = Source;
dv.Sort = ViewState["sortexpression"].ToString() + " " + ViewState["sortdirection"].ToString();
}
GridView1.DataSource = Source;
GridView1.PageSize = 4;
GridView1.DataBind();
}

If it is that easy, everybody will be doing it
   

- Advertisement -