Click here to Skip to main content
15,917,639 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a login windows where users enters username and password after that when the user press the Login button i want it to display fistname and lastname och the user in a two labels,

The problem is that the value of the user get null, why?

This code i have in my login Button
C#
private void LogIn()
        {
            
                
                var db = new DigitalFakturaDBEntities1();
                var s = (from p in db.Users
                    where p.Username == TextBoxÚsernameLoginIN.Text && p.Password == TextBoxPasswordLogin.Text
                    select p);
                
                if (s.Any())

                {
                    var user = new Users();
                    user.Firstname = LabelFirstnameDisplay.Text;
                }
                LabelErrorLogIn.Visible = false;
            }
Posted

1 solution

Why are you fetching what I assume is a list of users from your DB, and then ignoring it when you have checked if there are any in there?
C#
if (s.Any())
Checks if any users match, but you then create an empty user that is unrelated to any of them, and set it's firstname to an existing label that has nothing at all to do with the users you just looked for...
Perhaps you want to start with s and use that information as a basis for identifying your users?

And please, don't do it like that! Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]
 
Share this answer
 
Comments
Kurac1 30-Mar-14 5:34am    
Alright but doing like this , wont display the firstname in the label,
select p).FirstOrDefault();

if (s != null)
{
s.Firstname = LabelFirstnameDisplay.Text;
}
OriginalGriff 30-Mar-14 5:38am    
Well, no...it won't...because you are overwriting the Firstname in the User with the current value in the Label...
a = b;
assigns the value of "b" to the variable "a".
Perhaps you want:
LabelFirstnameDisplay.Text = s.Firstname;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900