日期:2014-05-17  浏览次数:20480 次

问一个Application的问题
C# code

private int getAdsCount(int position) {
        int count = 0;
        if (Application["pos_" + position] == null)   // 总是提示此行未将对象引用设置到对象。
        {
            SqlParameter[] param = { 
              new SqlParameter("@ChannelID",SqlDbType.Int,4),
              new SqlParameter("@AreaID",SqlDbType.Int,8),
              new SqlParameter("@CategoryID",SqlDbType.Int,8),
              new SqlParameter("@CategoryB",SqlDbType.Int,8),
              new SqlParameter("@PositionID",SqlDbType.BigInt,8)
        };

            param[0].Value = 4;
            param[1].Value = AreaID;
            param[2].Value = CategoryID;
            param[3].Value = CategoryB;
            param[4].Value = position;

            DataSet ds = PubPage.Common.SqlHelper_V1.ExecuteDataset(conn, CommandType.StoredProcedure, "sp_GetAdList", param);
            count = ds.Tables[0].Rows.Count;
            Application.Lock();
            Application["pos_" + position] = count;
            Application.UnLock();
        } else {
           count = Convert.ToInt32(Application["pos_" + position].ToString());
        }
        return count;
    }




Application这里应该怎么用?

------解决方案--------------------
Application是NULL了。getAdsCount函数是在什么类里面?
------解决方案--------------------

if (System.Web.HttpContext.Current.Application["pos_" + position] == null)

------解决方案--------------------
没有获取到 Application对象.