How to Create a Login Form With SQL Server in C# Form

Published: 14 April 2022
on channel: Tk CODE
4,569
45

#Csharp #WindowsForm #Form #WindowsFormExample #Coding #Programming
In this example I'll show you how to create a simple login form using SQL database.

The database I will use is MS SQL Server. I will tell you how to create connect a database and how to make a simple login form. To do this, just keep watching simple procedure.
....
Sometimes we use the login form for passing an other. At the end of the video I added a new form and tested again.

SQL Database Code:
use sampledb;

CREATE TABLE users(
id INT PRIMARY KEY IDENTITY(1,1),
username VARCHAR(50) NOT NULL,
userpass VARCHAR(50) NOT NULL
);

INSERT INTO users VALUES('mike','123456');

SELECT * FROM users;


C# Button Click Code:
private void button1_Click(object sender, EventArgs e)
{

cmd = new SqlCommand("select * from users where username=@username and userpass =@userpass", con);
cmd.Parameters.AddWithValue("@username", txtName.Text);
cmd.Parameters.AddWithValue("@userpass", txtPass.Text);

con.Open();

dr = cmd.ExecuteReader();

if(dr.HasRows)
{
Hide();//this form
Form2 form2 = new Form2();
form2.Show();
}
else
{
MessageBox.Show("Login Failure, Try Again!");
}

con.Close();
}


Watch video How to Create a Login Form With SQL Server in C# Form online without registration, duration hours minute second in high quality. This video was added by user Tk CODE 14 April 2022, don't forget to share it with your friends and acquaintances, it has been viewed on our site 4,569 once and liked it 45 people.