How to Create a Login Form in VB.NET using SQL Server Database and Visual Studio 2022? [Source code]
Login Form in VB.NET using SQL Database
Dim con As New SqlConnection("Data Source=YOUR-COMPUTER-NAME\SQLEXPRESS;Initial Catalog=loginform;Integrated Security=True;TrustServerCertificate=True") con.Open() Dim query As String = "SELECT COUNT(*) FROM loginform WHERE username=@username AND password=@password" Dim cmd As New SqlCommand(query, con) cmd.Parameters.AddWithValue("@username", txtUser.Text) cmd.Parameters.AddWithValue("@password", txtPass.Text) Dim count As Integer = Convert.ToInt64(cmd.ExecuteScalar) con.Close() If count > 0 Then MessageBox.Show("login successful", "info", MessageBoxButtons.OK, MessageBoxIcon.Information) Else MessageBox.Show("Login Error") End If //show passowrd: txtPass.UseSystemPasswordChar = Not CheckBox1.Checked close form: me.Close()