How to get multiple column values from DB in session variabl
I want to get UID, username, city, email from registration table (sql server) from DB on successful login of user.<br /> I want to store this values in session variables.<br /> <br /> <br /> plz help me with the code and solution<br /><div> below is my code</div><div> </div><div>protected void ValidateUser(object sender, EventArgs e)<br /> {<br /> int userId = 0;<br /> string constr = ConfigurationManager.ConnectionStrings[&quot;constr&quot;].ConnectionString;<br /> using (SqlConnection con = new SqlConnection(constr))<br /> {<br /> using (SqlCommand cmd = new SqlCommand(&quot;Validate_User&quot;))<br /> {<br /> cmd.CommandType = CommandType.StoredProcedure;<br /> cmd.Parameters.AddWithValue(&quot;@Username&quot;, txtUname.Text.Trim());<br /> cmd.Parameters.AddWithValue(&quot;@Password&quot;, txtPassword.Text.Trim());<br /> cmd.Connection = con;<br /> con.Open();<br /> SqlDataAdapter sda = new SqlDataAdapter(cmd);<br /> DataTable dt = new DataTable();<br /> sda.Fill(dt);<br /> userId = Convert.ToInt32(cmd.ExecuteScalar());<br /> con.Close();<br /> if (dt.Rows.Count &gt; 0)<br /> {<br /> Session[&quot;uid&quot;] = dt.Columns[0].ToString();<br /> Session[&quot;Username&quot;] = dt.Columns[1].ToString();<br /> Session[&quot;city&quot;] = dt.Columns[2].ToString();<br /> Response.Redirect(&quot;Redirectform.aspx&quot;);<br /> Session.RemoveAll();<br /> }<br /> else<br /> {<br /> lblmsg.Text = &quot;You're username and word is incorrect&quot;;<br /> lblmsg.ForeColor = System.Drawing.Color.Red;<br /> <br /> } <br /> }<br /> switch (userId)<br /> {<br /> case -1:<br /> lblmsg.Text = &quot;Username and/or password is incorrect.&quot;;<br /> break;<br /> case -2:<br /> lblmsg.Text = &quot;Account has not been activated.&quot;;<br /> break;<br /> default:<br /> //FormsAuthentication.RedirectFromLoginPage(Login1.UserName, Login1.RememberMeSet);<br /> break;<br /> }<br /> }<br /> }<br /> <br /> <br /> This is my stored Procedure..validated user<br /> <br /> ALTER PROCEDURE [dbo].[Validate_User]<br /> @Username NVARCHAR(20),<br /> @Password NVARCHAR(20)<br /> AS<br /> BEGIN<br /> SET NOCOUNT ON;<br /> DECLARE @UserId INT, @LastLoginDate DATETIME<br /> <br /> SELECT @UserId = UserId, @LastLoginDate = LastLoginDate<br /> FROM Users WHERE Username = @Username AND [Password] = @Password<br /> <br /> IF @UserId IS NOT NULL<br /> BEGIN<br /> IF NOT EXISTS(SELECT UserId FROM UserActivation WHERE UserId = @UserId)<br /> BEGIN<br /> UPDATE Users<br /> SET LastLoginDate = GETDATE()<br /> WHERE UserId = @UserId<br /> SELECT @UserId [UserId] -- User Valid<br /> END<br /> ELSE<br /> BEGIN<br /> SELECT -2 -- User not activated.<br /> END<br /> END<br /> ELSE<br /> BEGIN<br /> SELECT -1 -- User invalid.<br /> END<br /> END </div><div> </div>