Object reference required for non-static field, method, or property

后端 未结 3 1287
余生分开走
余生分开走 2021-01-18 22:14

I want to use the Caching.Cache(...) method, like so:

Cache.Insert(\"Interview Questions\", datatable, sqlcachedep)

or

Syst         


        
相关标签:
3条回答
  • 2021-01-18 22:25

    Try this (from memory):

    HttpApplication.Context.Cache.Insert("Reading List", datatable, sqlcachedep);
    
    0 讨论(0)
  • 2021-01-18 22:38

    It's saying the correct thing. You should try something like:

    HttpContext.Current.Cache.Insert(...);
    

    Cache.Insert is a not a static method (static methods are indicated by an "S" near the method icon in the documentation.) You need an instance to call the Insert method on. HttpContext.Current.Cache returns the Cache object associated with the current application.

    0 讨论(0)
  • You need to do

    Page.Cache.Insert()
    

    (I'm assuming you're talking ASP.Net). You're calling on Cache as the class, not as the instance of it.

    0 讨论(0)
提交回复
热议问题