#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();
}
Смотрите видео How to Create a Login Form With SQL Server in C# Form онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Tk CODE 14 Апрель 2022, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 4,569 раз и оно понравилось 45 людям.