今天在书上看了数据缓存,就学着写了一个例子,留作以后参考,同时也欢迎各路高手路过时,教我一些更有难度的,呵呵!
CommonData data = new CommonData(); //我自己写的一个类,用于取DataTable的
DataTable dt 
= null;
dt 
= (DataTable)Context.Cache["JobParentCategory"]; //Context.Cache -> System.Web
if (dt == null)
{
  dt 
= data.JobParentCategory();
  Context.Cache.Insert(
"JobParentCategory", dt); //把数据存入Cache中
}
foreach (DataRow dr in dt.Rows) //如果dt不为空,就直接遍历Cache中的DataTable
{
  ddlJobCategory.Items.Add(
new ListItem(dr[2].ToString(), dr[1].ToString()));
}

相关文章:

  • 2021-12-19
  • 2022-01-07
  • 2022-01-07
猜你喜欢
  • 2021-12-19
  • 2022-12-23
  • 2021-12-19
  • 2021-11-16
  • 2021-12-19
  • 2021-12-19
  • 2021-12-19
相关资源
相似解决方案