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 do i select UserName from table account and also select department in Department table and pass<p>Hi micah,</p> <p>Refer the below query. Using the query fetch the UserName and DepartmentName of that particular user from account and department table and assign that to the session variable when click the login button.</p> <pre class="brush: sql">DECLARE @Account AS TABLE(Id INT,UserName VARCHAR(20),Password VARCHAR(20)) INSERT INTO @Account VALUES(1,&#39;Steve1&#39;,&#39;steve@123&#39;) DECLARE @Department AS TABLE(Id INT,UserName VARCHAR(20),Department VARCHAR(20)) INSERT INTO @Department VALUES(1,&#39;Steve1&#39;,&#39;Sales&#39;) SELECT a.UserName,a.Password,d.Department FROM @Account a JOIN @Department d ON d.UserName = a.UserName WHERE a.UserName = &#39;Steve1&#39;</pre> <p><span style="text-decoration: underline;">OutPut</span></p> <p><strong>UserName&nbsp;&nbsp; &nbsp;Password&nbsp;&nbsp; &nbsp;Department</strong></p> <p>Steve1&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; steve@123&nbsp;&nbsp; &nbsp;Sales</p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/160318/How-do-i-select-UserName-from-table-account-and-also-select-department-in-Department-table-and-pass/https://www.aspforums.net:443/Threads/160318/How-do-i-select-UserName-from-table-account-and-also-select-department-in-Department-table-and-pass/Mon, 28 Mar 2016 02:39:59 GMTHow do i select UserName from table account and also select department in Department table and pass<p>i tried your example on my storedprocedure login to fetch the account from user table and fetch the ad name from company account</p> <p>&nbsp;</p> <pre class="brush: sql">ALTER PROCEDURE [dbo].[Validate_User5] @UserName NVARCHAR(200), @Password NVARCHAR(200) AS BEGIN SET NOCOUNT ON; DECLARE @UserId INT, @LastLoginDate DATETIME DECLARE @User3 AS TABLE(Id INT,UserName VARCHAR(20),LastLogin DATETIME,Password VARCHAR(20)) DECLARE @CompanyInfo AS TABLE(Id INT,UserName VARCHAR(20),Name VARCHAR(20)) SELECT a.Id,a.UserName,a.Password,a.LastLogin,d.Name FROM @User3 a JOIN @CompanyInfo d ON d.UserName = a.UserName WHERE a.UserName = @UserName IF @UserId IS NOT NULL BEGIN SELECT 1 -- User available. END ELSE BEGIN SELECT -1 -- User not available. END END</pre> <p>Now i have the login code which uses session</p> <p>&nbsp;</p> <pre class="brush: csharp"> int UserID; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(&#34;Validate_User5&#34;)) { using (SqlDataAdapter sda = new SqlDataAdapter()) { cmd.CommandType = CommandType.StoredProcedure; Session[&#34;UserName&#34;] = ctlLogin.UserName; Session[&#34;Name&#34;] = ctlLogin.UserName; // cmd.Parameters.AddWithValue(&#34;@Email&#34;, ctlLogin.UserName); cmd.Parameters.AddWithValue(&#34;@UserName&#34;, ctlLogin.UserName); cmd.Parameters.AddWithValue(&#34;@Password&#34;, (ctlLogin.Password));</pre> <p>now on page i have the code that help me to navigae to the very ad page of the user by clicking the company name and its not working only username is working</p> <p>&nbsp;</p> <pre class="brush: csharp"> public string getUserHREF(object sURL) { DataRowView dRView = (DataRowView)sURL; string username = dRView[&#34;Name&#34;].ToString(); return ResolveUrl(&#34;~/ADPage.aspx?Id=&#34; + username); }</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/160318/How-do-i-select-UserName-from-table-account-and-also-select-department-in-Department-table-and-pass/https://www.aspforums.net:443/Threads/160318/How-do-i-select-UserName-from-table-account-and-also-select-department-in-Department-table-and-pass/Mon, 28 Mar 2016 05:19:25 GMTHow do i select UserName from table account and also select department in Department table and pass<p>First you are asking Account with Department Table now you are changing your requirement. I would suggest you create new procedure for getting the UserName and the DepartmentName using my given query, after user successfully loged in then using the procedure fetch the record from database and assign the value to session variable like below.</p> <pre class="brush: csharp">Session[&#34;UserName&#34;] = dr[&#34;UserName&#34;].ToString(); Session[&#34;Department&#34;] = dr[&#34;Department&#34;].ToString();</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/160318/How-do-i-select-UserName-from-table-account-and-also-select-department-in-Department-table-and-pass/https://www.aspforums.net:443/Threads/160318/How-do-i-select-UserName-from-table-account-and-also-select-department-in-Department-table-and-pass/Mon, 28 Mar 2016 05:45:07 GMTHow do i select UserName from table account and also select department in Department table and pass<p>Thanks the code worked.</p>https://www.aspforums.net:443/Threads/160318/How-do-i-select-UserName-from-table-account-and-also-select-department-in-Department-table-and-pass/https://www.aspforums.net:443/Threads/160318/How-do-i-select-UserName-from-table-account-and-also-select-department-in-Department-table-and-pass/Mon, 28 Mar 2016 05:54:53 GMT