Lets we see how to create a login page in C#.NET. The Beginners can easily create a login page in C#.net using the following Steps
Steps:
- Create a Database in SQL Server 2005
- Create a C#.net project in c#.net
- Connect the Created Database with the Created C#.net project
- Generate Code
- Check the Login page(Testing)
Step 1: Create a Database in SQL Server 2005
Give your correct local Server name, Username and Password
After that you can see the following window
Then follow the steps:
Give the Database name as Login
Now the Database has been created successfully. The following steps will show the table creation in SQL Server. Double click the Database, Now you can see the following window and select the table
Column Creation
Give a name for Table
Created Table
Open the Table
Entering Contents into the Table
Step 2: Create a C#.net project in c#.net
Open visual studio
Create a new project
Choose Visual C# windows application
Give the Project name
Place controls on form
Now the project has been created...!
Step 3: Connect the Created Database with the Created C#.net project
Give the correct servername , Username and password The Servername, Username,Password all are same as the sqlserver 2005
Choose the Use SQL Server Authentication
After entering Correct servername,Username and Password you can choose the Database form list of Databases
Choose the Login Database
Check the Connection
Step 4: Generate Code
Add the namespace : using System.Data.SqlClient;
The connection String is mus need for connect the Database with our project
Click the server explorer and then click the login database
Now you can see the connection string in properties window:
Copy the Connection string and paste it in the code window
Now click F5 to check the Database Connection
Now Copy the Following code and paste it with in the button click method
if (textBox1.Text == "" || textBox2.Text == "")
{
}
else
{
SqlCommand scmd;
SqlDataReader sdr;
scmd = new SqlCommand("select Username,Password from tbl_Check where USername=@Username and Password=@Password",sc);
scmd.Parameters.AddWithValue("@Username",textBox1 .Text .ToString ());
scmd.Parameters.AddWithValue("@Password",textBox2 .Text .ToString ());
sdr = scmd.ExecuteReader();
if (sdr.HasRows)
{
sdr.Close();
MessageBox.Show("Welcome- The Username and Password is Correct", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Invalid Username or Password", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
Step 5: Check the Login page(Testing)
Give the Correct username and password, that is already stored in the tbl_Check table
Give the Wrong username and Password
The Beginners can use this way to create a simple Login page