Click here to Skip to main content
13,703,177 members
Rate this:
 
Please Sign up or sign in to 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 4-Nov-17 19:45pm
Updated 4-Nov-17 20:43pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.[^]
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Your SQL should be :
select count(*) from LoginInfo where Username = @uname and password = @pwd
Use AND instead of ,
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Above Answers are the correct...
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web06-2016 | 2.8.180906.1 | Last Updated 5 Nov 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100