Storing a DataRow into a Session (server) variable

I recently ran into a situation where I needed to store a DataRow object, which is not serializable, into a Session variable using the Session Server.  As I mentioned yesterday, all sessions should be stored to either the Session Server or the SQL Session Server.  This means that all of the objects being stored must be serializable.

My problem stemmed from the fact that a DataRow is not Serializable and there is no clean mechanism for it to become serializable.

However, a DataTable is serializable.  So, the simple solution is to:

  • Create a DataTable object
  • Add the DataRow to the Table
  • Store the DataTable in the Session variable.

To get the row out, you reverse the process.

  • Retrieve the DataTable from the Session object
  • Cast the object to a DataTable
  • Retrieve the first row from the table.

Related Post

Leave a Reply

Comment Policy:

  • You must verify your comment by responding to the automated email that is sent to your email address. Unverified comments will never show.Leave a good comment that adds to the conversation and I'll leave your link in.
  • Leave me pure spam and I'll delete it.
  • Leave a general comment and I'll remove the link but keep the comment.

Notify me of followup comments via e-mail