![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIml2Zus2YvxmQkVGdjFmc052bD9CXzJ3b0F2YpRmbJdmbp5WasRXdP9CXzV2Zh1WSvwVbvNmLzd2bsJmbj5yd3d3Lc9CX6MHc0RHaiojIsJye.gif)
Code
/// <summary>
/// 從緩存中讀取DataTable
/// </summary>
/// <param name="cacheKey">cache key</param>
/// <param name="strWhere">SQL語句條件</param>
/// <returns></returns>
/// <date>
/// 2009-04-21建立
/// </date>
public static DataTable BuildDataTable(string cacheKey, string strWhere)
{
DataTable dt=null;
Cache cache = HttpRuntime.Cache;
if (cache[cacheKey] != null)
{
dt = (DataTable)cache[cacheKey];
}
else
{
dt = GetDtFromDataBase(strWhere);
}
cache.Insert(cacheKey, dt, null, DateTime.Now.AddMinutes(30), TimeSpan.Zero);
return dt;
}
轉載于:https://www.cnblogs.com/cry/archive/2009/04/22/1440945.html