我正在使用MVC3并从数据库获取国家/地区表并存储在缓存中。第一次从缓存中获取数据但是当我刷新页面时,它只给我数据表模式。它只给我字段countryid,countryname,countrycode。但它没有给我数据。
DataTable dt_Country = (DataTable)HttpContext.Current.Cache["Countries"];
if (dt_Country == null)
{
DataTable dt_State1 = new DataTable();
SqlConnection con = new SqlConnection(Common.ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("ConstantsCountriesSelectAll", con);
SqlDataAdapter ada = new SqlDataAdapter(cmd);
ada.Fill(dt_State1);
HttpContext.Current.Cache["Countries"] = dt_State1;
dt_Country = (DataTable)HttpContext.Current.Cache["Countries"];
}
//dt_Country = (DataTable)HttpContext.Current.Cache["Countries"];
return dt_Country;