2

我正在使用 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;
4

0 回答 0