Creating Understanding and Educating Programmers, Developers and Technical Communities, one post at a time.

Friday, May 29, 2009

[Quick Tip] Session

During the development of Asp.Net application, developer don't need to instantiate any session. Session is automatically instantiated, you need to use them according to your requirement. Here, I am going to show you one simple example.

DataTable dt = new DataTable();

// what ever the table you want to put in dt

// assign dt value into session variable, make sure it is unique name,
// I have given dtSessionVariable as session variable name.
Session["dtSessionVariable"] = dt;


// To retrieve it from session, it require casting back to original type
DataTable dt = (DataTable)Session["dtSessionVariable"];

2 comments:

  1. Nice post but putting big chunks of data in session like a data table is not the best thing to do!!!

    ReplyDelete
  2. @Anonymous: You are right. It will make application slower.

    ReplyDelete