I am trying to cache a data table.
In this code snippet I try to find out whether the cached datatable exists, if not I will create a table, load data and add it to the cache.
Cache cache = new Cache();
DataTable dt = new DataTable();
dt = (DataTable)cache.Get("MyTa
ble");
if (dt==null)
{
//create data table, load data and add to cache.
}
The problem is that code gives an error on line dt = (DataTable)cache.Get("MyTa
ble");
System.NullReferenceExcept
ion: Object reference not set to an instance of an object
What am I overlooking here? Thanks!
Start Free Trial