Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SqlConnection conn = new SqlConnection(@"server=DELL-PC\SQLEXPRESS;Database=WinApp;Integrated Security = true");
            SqlCommand cmd = new SqlCommand("select count(*) from LoginInfo where Username = @uname, password = @pwd",conn);
            cmd.Parameters.Add(new SqlParameter("@uname", lblunametxt.Text));
            cmd.Parameters.Add(new SqlParameter("@pwd", lblpwdtxt.Text));
            conn.Open();
            int noOfRowsAffected = (int)cmd.ExecuteScalar();
            conn.Close();
            
            if(noOfRowsAffected > 0)
            {
                MDIParent md = new MDIParent();
                md.Show();
                this.Hide();
            }

            else
            {
                Console.Write(" invalid credentials");
            }


What I have tried:

SqlConnection conn = new SqlConnection(@"server=DELL-PC\SQLEXPRESS;Database=WinApp;Integrated Security = true");
            SqlCommand cmd = new SqlCommand("select count(*) from LoginInfo where Username = @uname, password = @pwd",conn);
            cmd.Parameters.Add(new SqlParameter("@uname", lblunametxt.Text));
            cmd.Parameters.Add(new SqlParameter("@pwd", lblpwdtxt.Text));
            conn.Open();
            int noOfRowsAffected = (int)cmd.ExecuteScalar();
            conn.Close();
            
            if(noOfRowsAffected > 0)
            {
                MDIParent md = new MDIParent();
                md.Show();
                this.Hide();
            }

            else
            {
                Console.Write(" invalid credentials");
            }
Posted
Updated 4-Nov-17 20:43pm

Mehdi is right that your SQL is wrong: comma is not valid as part of an WHERE clause.

But ... 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
 
Your SQL should be :
SQL
select count(*) from LoginInfo where Username = @uname and password = @pwd
Use AND instead of ,
 
Share this answer
 
Above Answers are the correct...
 
Share this answer
 
Comments
Richard Deeming 6-Nov-17 12:28pm    
Yes, they are. But your "answer" doesn't add anything to them.

If you want to show your support or appreciation for an answer, you can use the star rating on the top-right of the answer to rate it, and you can click the "Have a Question or Comment?" button under the answer to add a comment.

But unless you're adding more information to the discussion, DO NOT post your comment as a "solution"!

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