ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.How to store and retrieve multiple values in a single Session in ASP.Net<p>Hi <a class="username" rel="safal"> safal</a>,</p> <p>Refer the below code.</p> <pre class="brush: csharp">// After login store the details in hashtable and then pass the hashtable to session. System.Collections.Hashtable ht = new System.Collections.Hashtable(); ht.Add(&#34;UId&#34;, &#34;123&#34;); ht.Add(&#34;UserName&#34;, &#34;Test Name&#34;); ht.Add(&#34;City&#34;, &#34;Test City&#34;); Session[&#34;EmployeeInfo&#34;] = ht; // You can retrive the value from session in your application. if (Session[&#34;EmployeeInfo&#34;] != null) { System.Collections.Hashtable userDetails = (System.Collections.Hashtable)Session[&#34;EmployeeInfo&#34;]; string userId = userDetails.ContainsKey(&#34;UId&#34;) ? Convert.ToString(userDetails[&#34;UId&#34;]) : string.Empty; string userName = userDetails.ContainsKey(&#34;UserName&#34;) ? Convert.ToString(userDetails[&#34;UserName&#34;]) : string.Empty; string city = userDetails.ContainsKey(&#34;City&#34;) ? Convert.ToString(userDetails[&#34;City&#34;]) : string.Empty; }</pre> <p>Or you can make a class for that and store the value in it and pass the class object to the session.</p> <pre class="brush: csharp">// After login store the details in class object and then pass the object to session. EmployeeInfo ei = new EmployeeInfo(); ei.Id = "123"; ei.Name = "Test Name"; ei.City = "Test City"; Session["EmployeeInfo"] = ei; // You can retrive the value from session in your application. if (Session["EmployeeInfo"] != null) { EmployeeInfo eiDetails = (EmployeeInfo)Session["EmployeeInfo"]; string userId = !string.IsNullOrEmpty(eiDetails.Id) ? eiDetails.Id : string.Empty; string userName = !string.IsNullOrEmpty(eiDetails.Name) ? eiDetails.Name : string.Empty; string city = !string.IsNullOrEmpty(eiDetails.City) ? eiDetails.City : string.Empty; } public class EmployeeInfo { public string Id { get; set; } public string Name { get; set; } public string City { get; set; } }</pre> <p>If in case of there would be possibility of increase the property then i would suggest you go with the 2nd option i.e. creating class object.</p>https://www.aspforums.net:443/Threads/442264/How-to-store-and-retrieve-multiple-values-in-a-single-Session-in-ASPNet/https://www.aspforums.net:443/Threads/442264/How-to-store-and-retrieve-multiple-values-in-a-single-Session-in-ASPNet/Thu, 06 Oct 2016 02:40:38 GMTHow to store and retrieve multiple values in a single Session in ASP.Net<p>Thank you sir for your guidance..</p> <p>But still&nbsp; i have some doubt</p> <p>As i am only passing only two values username and password for login&nbsp; by using stored procedure.</p> <p>by comparing this values in userTable..&nbsp;</p> <p>now i wan't to retrieve uid, username, password, city, email from usertable ..</p> <p>and store this values in session varibales to display on other pages.</p> <p>Is there any changes i have to make in my SP query or sql statement.</p> <p>or there is something wrong in c# code..</p> <p>please suggest changes</p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/442264/How-to-store-and-retrieve-multiple-values-in-a-single-Session-in-ASPNet/https://www.aspforums.net:443/Threads/442264/How-to-store-and-retrieve-multiple-values-in-a-single-Session-in-ASPNet/Thu, 06 Oct 2016 03:07:23 GMTHow to store and retrieve multiple values in a single Session in ASP.Net<p>You can't ask multiple queries within a question. This is against forum rules and necessary to maintain clean forum.<br />It is requested Mark Answer the replies when question is answered and ask a new question as a responsible member to help fellow programmers around the world.<br />Note: If you don't mark answers, people will loose interest in your questions.</p>https://www.aspforums.net:443/Threads/442264/How-to-store-and-retrieve-multiple-values-in-a-single-Session-in-ASPNet/https://www.aspforums.net:443/Threads/442264/How-to-store-and-retrieve-multiple-values-in-a-single-Session-in-ASPNet/Thu, 06 Oct 2016 09:46:50 GMT