如何对保存在cache缓存里的datatable等进行修改? 如:id name num1 a 112 b 123 c 18这样一个datatable我存在cache里经常对某一条的num修改,重新从数据库里读再重建cache效率低怎么直接修改cache里table里的值阿 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如下这种方法如如何:利用Cache来做在线这样避免了频繁地读写数据库,但相应地增加了服务器内存的开销好在Online的开销不是很大,而且是应用程序级,但不知这两种方法孰优孰劣?源代码如下://保存在线public void SaveOnline(string userPlace){ DataTable online; if (HttpContext.Current.Cache["online"]==null) { online = new DataTable(); online.Columns.Add("onlineID",typeof(string)); online.Columns.Add("userID",typeof(string)); online.Columns.Add("userName",typeof(string)); online.Columns.Add("userLevelName",typeof(string)); online.Columns.Add("userLevelImg",typeof(string)); online.Columns.Add("userIP",typeof(string)); online.Columns.Add("userPlace",typeof(string)); online.Columns.Add("logoTime",typeof(DateTime)); online.Columns.Add("actionTime",typeof(DateTime)); online.Columns.Add("userOS",typeof(string)); online.Columns.Add("userCLR",typeof(string)); online.Columns.Add("userBorwser",typeof(string)); HttpContext.Current.Cache["online"] = online; } DataRow[] dr1; DataRow dr2; online = (DataTable)HttpContext.Current.Cache["online"]; dr1 = online.Select("onlineID='" + onlineID + "'"); if (dr1.Length>0) { dr1[0][1] = UserID; dr1[0][2] = UserName; dr1[0][4] = UserLevelImg; dr1[0][6] = userPlace; dr1[0][8] = DateTime.Now; online.AcceptChanges(); } else { dr2 = online.NewRow(); dr2[0] = onlineID; dr2[1] = UserID; dr2[2] = UserName; dr2[3] = userLevelName; dr2[4] = UserLevelImg; dr2[5] = UserIP; dr2[6] = userPlace; dr2[7] = DateTime.Now; dr2[8] = DateTime.Now; dr2[9] = UserOS; dr2[10] = UserCLR; dr2[11] = UserBrowser; online.Rows.Add(dr2); } DeleteOnline();}//清除超时用户private void DeleteOnline(){ DataTable online = (DataTable)HttpContext.Current.Cache["online"]; for (int i=0;i<online.Rows.Count;i++) { if (Convert.ToDateTime(online.Rows[i][7])<DateTime.Now.AddMinutes(-10.0)) online.Rows[i].Delete(); } online.AcceptChanges();} DataTable dt = ....;//获得dtCache["dt"] = dt;取值DataTable newDt = (DataTable)Cache["dt"]; 一直从Cache里面取出DataTable之后,就当作一般的DataTable一样修改,就行了。Cache存放在线表这种做法没有问题。 dim tb as datatable=ctype(cache("表的缓存名"),datatable)这样你就可以对tb操作。 Cache["dt"] = dt;DataTable newDt = (DataTable)Cache["dt"]; //****你将放在catch的datagable数据放到一个datagrid控件上,然后在datagrid进行修改数据就可以了三. 【分享】蜗牛控件2-无代码绑定数据 页面中的服务器端控件为何不自动在designer.cs文件中生成了? 出学.NET 问个简单问题 js可以让ASP.NET Forms验证产生的COOKIE失效么? 百度创意专家是用何种技术来实现的? 服务器上出现应用程序错误(急) 请问大家如何实现页面后退时该页无法显示 请问DATAVIEW能设定显示的行数吗? 为什么页面一开始时就会执行unload事件,反而关闭这个页面时不执行? vs2013使用razor引擎为什么总是强制生成一个form元素?软件BUG? 企业网站的开发常识,我该从哪里入手呢,请高手指教,非常感谢 2005中如何修改项目名称
这样避免了频繁地读写数据库,但相应地增加了服务器内存的开销
好在Online的开销不是很大,而且是应用程序级,但不知这两种方法孰优孰劣?源代码如下://保存在线public void SaveOnline(string userPlace)
{
DataTable online;
if (HttpContext.Current.Cache["online"]==null)
{
online = new DataTable();
online.Columns.Add("onlineID",typeof(string));
online.Columns.Add("userID",typeof(string));
online.Columns.Add("userName",typeof(string));
online.Columns.Add("userLevelName",typeof(string));
online.Columns.Add("userLevelImg",typeof(string));
online.Columns.Add("userIP",typeof(string));
online.Columns.Add("userPlace",typeof(string));
online.Columns.Add("logoTime",typeof(DateTime));
online.Columns.Add("actionTime",typeof(DateTime));
online.Columns.Add("userOS",typeof(string));
online.Columns.Add("userCLR",typeof(string));
online.Columns.Add("userBorwser",typeof(string));
HttpContext.Current.Cache["online"] = online;
}
DataRow[] dr1;
DataRow dr2;
online = (DataTable)HttpContext.Current.Cache["online"];
dr1 = online.Select("onlineID='" + onlineID + "'");
if (dr1.Length>0)
{
dr1[0][1] = UserID;
dr1[0][2] = UserName;
dr1[0][4] = UserLevelImg;
dr1[0][6] = userPlace;
dr1[0][8] = DateTime.Now;
online.AcceptChanges();
}
else
{
dr2 = online.NewRow();
dr2[0] = onlineID;
dr2[1] = UserID;
dr2[2] = UserName;
dr2[3] = userLevelName;
dr2[4] = UserLevelImg;
dr2[5] = UserIP;
dr2[6] = userPlace;
dr2[7] = DateTime.Now;
dr2[8] = DateTime.Now;
dr2[9] = UserOS;
dr2[10] = UserCLR;
dr2[11] = UserBrowser;
online.Rows.Add(dr2);
}
DeleteOnline();
}
//清除超时用户
private void DeleteOnline()
{
DataTable online = (DataTable)HttpContext.Current.Cache["online"];
for (int i=0;i<online.Rows.Count;i++)
{
if (Convert.ToDateTime(online.Rows[i][7])<DateTime.Now.AddMinutes(-10.0))
online.Rows[i].Delete();
}
online.AcceptChanges();
}
Cache["dt"] = dt;取值
DataTable newDt = (DataTable)Cache["dt"];
这样你就可以对tb操作。