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.Get Logged In User details in WPF Application using C#<p>Hi&nbsp;bigbear,</p> <p>Instead of returning boolean value from&nbsp;UserLogin function return string or integer value based on your datatype.</p> <p>Then you can check the condition on button click for null or empty vale and fetch the User details.</p> <p>Refer the below modified code.</p> <pre class="brush: csharp">private void BtnLoginUser_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(txtUsername.Text)) { //verify and enter username. MessageBox.Show(&#34;Enter your username.&#34;, &#34;Empty&#34;, MessageBoxButton.OK, MessageBoxImage.Information); txtUsername.Focus(); return; } else if (string.IsNullOrEmpty(txtPassword.Password)) { MessageBox.Show(&#34;Enter your password.&#34;, &#34;Empty&#34;, MessageBoxButton.OK, MessageBoxImage.Information); txtPassword.Focus(); return; } else { try { if (!string.IsNullOrEmpty(SQLuserAccess.UserLogin(txtUsername.Text, txtPassword.Password))) { MessageBox.Show(&#34;Login success&#34;); string userId = SQLuserAccess.UserLogin(txtUsername.Text, txtPassword.Password); User user = new User(); user = SQLuserAccess.GetUserById(Convert.ToInt32(userId)); } else { MessageBox.Show(&#34;Login Failed&#34;); } } } } //SQL login method public static string UserLogin(string username, string password) { string result; //SQL Login Query. string SQLloginQuery = &#34;SELECT UserId FROM Users WHERE Username=@username AND Password=@password&#34;; SqlCommand cmdLogin = new SqlCommand(SQLloginQuery, connection); cmdLogin.Parameters.AddWithValue(&#34;@username&#34;, username); cmdLogin.Parameters.AddWithValue(&#34;@password&#34;, password); try { connection.Open(); result = Convert.ToString(cmdLogin.ExecuteScalar()); } catch (Exception ex) { ex.Message.ToString(); throw ex; } finally { connection.Close(); } return result; } //This is a method I use to get the user public static User GetUserById(int userId) { string SQLreadQuery = &#34;SELECT Username, Password, IsAdmin, UserCreatedDate &#34; + &#34;FROM Users WHERE UserId = &#34; + userId; //or SELECT each column or *. SqlCommand cmdRead = new SqlCommand(SQLreadQuery, connection); try { connection.Open(); SqlDataReader reader = cmdRead.ExecuteReader(CommandBehavior.SingleRow); if (reader.Read()) { User user = new User(); user.UserID = userId; user.Username = reader[&#34;Username&#34;].ToString(); user.Password = reader[&#34;Password&#34;].ToString(); user.IsAdmin = Convert.ToBoolean(reader[&#34;IsAdmin&#34;]); user.UserCreatedDate = Convert.ToDateTime(reader[&#34;UserCreatedDate&#34;]); return user; } else { return null; } } catch (Exception ex) { ex.Message.ToString(); return null; } finally { connection.Close(); } }</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/126712/Get-Logged-In-User-details-in-WPF-Application-using-C/https://www.aspforums.net:443/Threads/126712/Get-Logged-In-User-details-in-WPF-Application-using-C/Mon, 05 Nov 2018 02:41:53 GMT