c# - How to show user login name on the next page -
When you open the application, my first screen is logged as you have 10 and There are pages. I want the name of the person who is logged into all pages (Welcome, User!). I have no idea how to do this
This is my code:
Private zero btnLogin_Click (Object Sender, RoutedEventArgs e) {txtUsername.IsEnabled = true; TxtPassword.IsEnabled = true; TxtMessage.Text = ""; TxtMessage.IsEnabled = false; Try {SqlConnection Okonation = New SqlConnection (_ConnectionString); SqlCommand oCommand = New SqlCommand ("Choose from the register where the user's name = '" + txtUsername.Text + "' and password = '" + txtPassword.Password + "' ',' oConnection); if (oConnection.State == ConnectionState.Closed) oConnection.Open (); SqlDataAdapter Adapter = New SqlDataAdapter (); SqlDataReader Reader = oCommand.ExecuteReader (); String Username = Null; if (reader.HasRows) {username = txtUsername.Text; oConnection.Close ( ); Navigation service _Navi = Navigation service.NET Navigation service (this); _Nav.Navigate (New URI ("Menuxaml.xaml", UriKind.RelativeOrAssolute)); and if (txtUsername.Text.Trim (). Length == 0) Errormessage.Text = "Please enter your username "; Else if (txtPassword.Password.Trim (). Length == 0) Errormessage.Text =" Please enter your password "; Else {Errormessage.Text =" Invalid user name or password! "; TxtPassword.Password = ""; TxtUsername.Text = "";} OConnection.Close ();}}
< P> If you need a user name in all 10 pages, then I will suggest you to add it to application resources and get it from all applications. Let me tell you how to do this.
Application.Current.Resources.Add ("user name", txtUsername.Text); And then use this resource to set your labels on your second page.
lbl.Content = Application.Current.Resources ["UserName"];
Comments
Post a Comment