- if (Cache["MyDataSet"]==null)
-
{
-
-
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["mtiladminConnectionString"].ConnectionString);
-
SqlDataAdapter mydataadapter = new SqlDataAdapter("select intproductid,vchproductname,vchproductacctype,vchprodacclogoimg from productmaster order by intproductid desc", con);
-
-
-
-
mydataadapter.Fill(ds, "Authors");
-
-
SqlCacheDependency dependency = new SqlCacheDependency("mtiladmin", "productmaster");
-
//System .Web .Caching .CacheDependency dependency= new System.Web.Caching.CacheDependency(
-
//Server.MapPath("MyDataSet.xml"));
-
-
Cache.Insert("mydataset", ds, dependency);
-
-
//Cache.Insert("MyDataSet", ds,
-
// dependency,
-
// DateTime.Now.AddMinutes(2), TimeSpan.Zero,
-
// CacheItemPriority.High, null);
-
-
-
-
-
viewgrid.DataSource = Cache["MyDataSet"] as DataSet ;
-
viewgrid.DataBind();
-
//Response.Write(" from table");
-
-
}
-
else if (Cache["MyDataSet"] != null)
-
{
-
// DataView view = new DataView();
-
-
DataSet ds1 = new DataSet();
-
ds1 =Cache["MyDataSet"] as DataSet ;
-
-
-
//ds = new DataSet(view);
-
viewgrid.DataSource = ds1;
-
viewgrid.DataBind();
-
//Response.Write("from cache");
-
-
}
when i update row , cache object are not updating
3 5400
when i update row on first click it is not updataing , it shows previous data, on secon click it is updating
my ciode is -
public void bindgrid()
-
{
-
-
DataSet myCustomers;
-
myCustomers = (DataSet)Cache["MyDataSet"];
-
-
if (myCustomers == null)
-
{
-
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["mtiladminConnectionString"].ConnectionString);
-
SqlDataAdapter mydataadapter = new SqlDataAdapter("select intproductid,vchproductname,vchproductacctype,vchprodacclogoimg from productmaster order by intproductid desc", con);
-
-
myCustomers = new DataSet();
-
mydataadapter.Fill(myCustomers, "Customers");
-
SqlCacheDependency dependency = new SqlCacheDependency("mtiladmin", "productmaster");
-
Cache.Insert("MyDataSet", myCustomers, dependency);
-
-
-
}
-
-
-
viewgrid.DataSource = myCustomers;
-
viewgrid.DataBind();
-
-
-
////////////////////////////////////
-
-
} }
-
-
protected void viewgrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
-
{
-
//Cache["MyDataSet"]="" ;
-
-
int ID = Int32.Parse(viewgrid.DataKeys[e.RowIndex].Values[0].ToString());
-
TextBox txtpath1 = (TextBox)viewgrid.Rows[e.RowIndex].FindControl("txtprodname");
-
TextBox txtpath2 = (TextBox)viewgrid.Rows[e.RowIndex].FindControl("txtproductacctype");
-
TextBox txtpath18 = (TextBox)viewgrid.Rows[e.RowIndex].FindControl("txtprodacclogoimg");
-
string query = "update productmaster set vchproductName='" + txtpath1.Text + "',vchproductacctype='" + txtpath2.Text + "',vchprodacclogoimg='" + txtpath18.Text + "' where intproductid=" + ID;
-
SqlCommand cmd1 = new SqlCommand(query, con);
-
cmd1.Connection.Open();
-
cmd1.ExecuteNonQuery();
-
viewgrid.EditIndex = -1;
-
-
bindgrid();
-
}
When you updated the row, did you update the XML file you are using as a dependency?
Have you seen these articles According to the second article, you can have an item evicted from the cache when a file changes....once the item is evicted you can recreate it.
In your code for updating:
You are updating the data source and then when you are finished you are binding (different/old) data to the GridView.
When you are binding the data to your GridView you are retrieving the data stored in Cache, not the data that you have just updated.
After updating, the data source will be evicted from Cache the next time someone attempts to access the page because you have changed the source. Since it's evicted, it will appear as Null/Nothing during the next request...when this happens your code is recreating the cached version of your data source.
Therefore, I would recommend not using the bindgrid() method when you are updating the row....you need to deal with the data source instead of the cached version of the data source in this section of your code.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: abdoly |
last post by:
i wrote a code to update datagrid with the datagrid updatecommand but i cant get the updated values after being update
that is the code
private void DataGrid1_UpdateCommand(object source,...
|
by: SMG |
last post by:
Hi there,
I want to update my cached dataset, if there is any change in database. I
know this is possible in case of ASP.Net 2.0 , But how do I execute the same
task with ASP.Net 1.0
As there...
|
by: Janaka |
last post by:
I tend to use the SqlDataAdapter class in WinForms projects because once the
inital data is loaded any modifications can be easily added/updated through
a call to the Update() method. I've found...
|
by: Charts |
last post by:
I used
HttpContext.Current.Cache To cache data from database.
The code is like that.
public static DataView GetCategories() {
if ( HttpContext.Current.Cache == null ) {...
|
by: William Sullivan |
last post by:
I'm trying to nail down some issues with the cache in my application.
Currently, I have an object that stands between my business logic and
database logic called CacheLogic (cute, no?). ...
|
by: Charles Law |
last post by:
Here's one that should probably have the sub-heading "I'm sure I asked this
once before, but ...".
Two users are both looking at the same data, from a database. One user
changes the data and...
|
by: Stan SR |
last post by:
Hi,
Some newbie questions.. :-)
First, what is the namespace to use for the Cache class ?
When I use this bit of code I get an error
if (Cache==null) Cache.Insert("myUserList",userlist);...
|
by: hharry |
last post by:
Hello All,
I save a Hashtable of stock symbols + prices to the cache. The prices
are updated every 30 minutes and saved to a database table.
I would like to always have the latest prices in...
|
by: teenagelcruise |
last post by:
hi,
i have a problem with my code which is i cannot update and addnew data into the database but i can delete the data.plz give me an idea.this is my code that i wrote.
<html>
<head>
<meta...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |