Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello,

Ive created a simple login windows form using VB.

At the moment all it does is checks what is entered into the text box against a set value if it is correct then login.

I am now trying not to have a set value and to actually get the login page to check against a number of usernames and passwords in a SQL database.

Any suggestions are appreciated.

Regards,

Glen.
Posted

1 solution

Consider the following example:
Suppose i have table tbleUserAuthentication, and two columns in this table i.e, Username and Password.
Following piece of code will help you to check information entered in Textbox against SQL Server.
C#
SqlConnection con = new SqlConnection("Your Connection Here");
SqlCommand cmd_retrvefrmDB = new SqlCommand("select * from tbleUserAuthentication where username=@u and Password=@p",con);
cmd_retrvefrmDB.Parameters.AddWithValue("@u",Your_UserName_TextBox.Text);
cmd_retrvefrmDB.Parameters.AddWithValue("@p",Your_UserPassword_TextBox.Text);
con.Open();
SqlDataReader dr = cmd_retrvefrmDB.ExecuteReader();
if (dr.Read())
{
         MessageBox.Show("User Logined. . .")
}
else
{
         MessageBox.Show("Invalid Username and Password. . .")
}
 
Share this answer
 

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