I have created the website in which i have to maintain the datatables & some variables in memory. Data/values in datatable or varibales will be different as per the logged user. how to maintain it?
You can save them as
DataTable dt = new DataTable();
// I assumed that dt has some data
Session["dataTable"] = dt; // Saving datatable to Session
// Retrieving
DataTable dtt = (DataTable) Session["dataTable"]; // Cast it to DataTable
int a = 43432;
Session["a"] = a;
// Retrieving
int aa = (int) Session["a"];
// classes
class MyClass
{
public int a { get; set; }
public int b { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
MyClass obj = new MyClass();
obj.a = 5;
obj.b = 20;
Session["myclass"] = obj; // Save the class object in Session
// Retrieving
MyClass obj1 = new MyClass();
obj1 = (MyClass) Session["myclass"]; // Remember casting the object
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With