The following procedure shows how to create a login form in Visual Studio and connect with SQL Server in 10 steps.
Step 1. Open any version of Visual Studio you have installed in your machine; I have Visual Studio 10. When open it will look like this.

Step 2. Click on the middle tab of a new project. When you click it will look like this.

Step 3. In Installed Templates, the first option is Visual C# language, and then select Windows Forms application.
In the following see the Name label and already show the default name WindowFormsApplication7.
You can change the name as you wish or as per program creation you can mention and click OK.
Step 4. After clicking OK a simple Windows Forms form will look like this.

Step 5. In your Windows Forms form set the size as needed. You can set the size and if you want to set the size by properties then right-click on the Windows Forms form and in the last option of show properties click to see the Windows Forms form properties.

Set the Windows Forms form name and show text in the specified properties. If you wish you can set the form1 name; my form1 name is “Log in Form”.
Click the Toolbox and drag and drop two buttons two labels and two TextBoxes as in the following.

Step 6. Then you need to change the lable1 name to User Name and label2 to Password then for the Buttons change the button1 right-click property to show text select button1 and type & login and button2 &Cancel. where & is used for a small Underline only one first text look up. See the image button1 to show the Log In and button2 to show Cancel for style.
Step 7. Now drag all text boxes and labels and buttons and arrange all the tools.
Then right-click each tool one by one and set the properties for font and color. Look at the following.

All sets of fonts and font sizes and if you want to set the image background set and form icon also you can set more things and tab index set serially for all tools of labels, TextBox, and buttons.

Now the final design looks like this type.
Step 8. To connect with a SQL Server database right-click on the form and click on properties then go to the upper second option (Data Binding). In Data Binding click the text area and it will look like this.

Now click on Add Project data Source.
Step 9. Then open these windows select “Database” click Next then select “Dataset” and click Next again select “Dataset” and click Next then click on New Connection then click the Refresh Button then select your SQL Server name. For example, my SQL name is KRISHNA-PC\SQLEXPRESS for the select radio button select or enter a database name for example my database name is STUDENT then click Test Connection and click the OK Button.
Click the connection string to show this type of connection string then select and copy then click on "Next" again click the Next tick table and the finish button now see the window:

This is SQL Server 2008 Database Details and show here the user id and Password. You use only these three passwords for this login form.

Step 10. This is the coding part of this application below.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace login_form
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection();
public Form1()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=KRISHNA-PC\\SQLEXPRESS;Initial Catalog=STUDENT;Integrated Security=True";
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'sTUDENTDataSet.login' table. You can move, or remove it, as needed.
//this.loginTableAdapter.Fill(this.sTUDENTDataSet.login);
SqlConnection con = new SqlConnection("Data Source=KRISHNA-PC\\SQLEXPRESS;Initial Catalog=STUDENT;Integrated Security=True");
con.Open();
{
}
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=KRISHNA-PC\\SQLEXPRESS;Initial Catalog=STUDENT;Integrated Security=True";
con.Open();
string userid = textBox1.Text;
string password = textBox2.Text;
SqlCommand cmd = new SqlCommand("select userid,password from login where userid='" + textBox1.Text + "'and password='" + textBox2.Text + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
MessageBox.Show("Login sucess Welcome to Homepage http://krishnasinghprogramming.nlogspot.com");
System.Diagnostics.Process.Start("http://krishnasinghprogramming.blogspot.com");
}
else
{
MessageBox.Show("Invalid Login please check username and password");
}
con.Close();
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
So friends this article will help you to create a Login Form in Visual Studio and connect with SQL Server. The next time I will put some more interesting commands, thank you. I hope this is helpful for you. Enjoy :).

Saroj MahantaPosted Oct 26, 2022, 11:44 AM
Thanks for this valuable information. Is it possible to do the same using Visual Studio Code ? I mean, to create an user registration web form, and write the data from the front end to the mysql database, using visual studio code editor.
Johnrey CanilloPosted Dec 11, 2020, 7:09 PM
Thank you for this procedure it helps me a lot.
Susanna GriegerPosted May 20, 2019, 12:02 PM
Where do I put the code you have in Step 10?
Abdul MajeedPosted Nov 14, 2018, 8:15 AM
Its nice ,It was the C# code Please send the VB.Net Program Code
Rushi MehtaPosted Oct 15, 2018, 7:54 AM
Very Nice Article
Seungwon HongPosted Aug 9, 2018, 3:20 PM
Good Article
FairProGamer FairProGamerPosted Feb 21, 2018, 1:08 AM
I meant not, not nto*.
FairProGamer FairProGamerPosted Feb 21, 2018, 1:08 AM
By the way, line 44, 50, and 51 of your code is very essential yet nto fully shown so we do not know what to do there I'm stuck plz fix that ASAP.
FairProGamer FairProGamerPosted Feb 21, 2018, 1:04 AM
Nicely done. i used this at my ojt internship and it worked out well. thanks man.
sujitha mPosted Aug 19, 2017, 1:10 AM
Hi Sir, I have a doubt.. You given a connection string in Public form, form load & button also... is it need that many times we need to give connection string? instead of that only we can give in button only rit???
Manav PandyaPosted May 31, 2017, 4:22 AM
Nice share ..............
Angry BirdPosted Mar 16, 2017, 9:55 AM
Vry good karishna rajpot singh
Thoko ChilongoPosted Feb 1, 2017, 2:36 AM
This has been of great help i was really stuck thanx
Ramesh PalaniappanPosted Sep 10, 2016, 9:42 AM
Good one
SubashPosted Jul 19, 2016, 8:59 AM
Thanks i try krishna
Krishna Rajput SinghPosted Mar 13, 2016, 5:07 AM
thanks Christopher Johnson for your valuable feedback i will do that
Christopher JohnsonPosted Mar 11, 2016, 11:05 PM
You really should use SQL Parameters instead of string concatenations to avoid SQL Injection.
Krishna Rajput SinghPosted Mar 3, 2016, 7:54 AM
http://krishnasinghprogramming.blogspot.in
Krishna Rajput SinghPosted Mar 3, 2016, 7:52 AM
http://krishnasinghprograming.blogspot.com
Gowtham KPosted Mar 2, 2016, 12:20 PM
Good One
Krishna Rajput SinghPosted Sep 7, 2015, 11:38 AM
thanks you so Ankur Chaturvedi
Ankur ChaturvediPosted Sep 4, 2015, 2:02 AM
Nice one
Krishna Rajput SinghPosted Aug 8, 2015, 6:46 PM
thanks for your valuable comments pranav kompally if you want to know more details visit here my personal blog i hope helpful for u http://krishnasinghprogramming.blogspot.com
Pranav KompallyPosted Aug 7, 2015, 12:03 PM
please do help me. Waiting forward for the email
Pranav KompallyPosted Aug 7, 2015, 12:02 PM
thank you so much for the above tutorial. Please can you send the source code files to my email i.e - [email protected]
Alain SeysPosted Apr 14, 2015, 1:21 PM
is there a way you can change the sql server trough a windows form , like if you put an app in production that uses the sql server but you need to change it name, like writing this data to the app.config or change the code behind it ?
Krishna Rajput SinghPosted Apr 6, 2015, 7:26 AM
thank you so much sumithra sumi and patel ajay and seigoulen haokip and Gowtham Rajamanickam for your valuable feedback and comments........
Gowtham RajamanickamPosted Apr 6, 2015, 4:14 AM
somply sooperb
Gowtham RajamanickamPosted Apr 6, 2015, 4:14 AM
nice
seigoulen HaokipPosted Apr 6, 2015, 2:46 AM
It's very helpful.
patel ajayPosted Jan 25, 2015, 5:17 AM
create login form in asp.net connect with sql server ? tell me
Krishna Rajput SinghPosted Nov 15, 2014, 11:40 AM
sure ask your question
sumithra sumiPosted Nov 15, 2014, 11:09 AM
so simple. oh my god. thank you so much. but i need some more explanation to give the priority to the users that can sign in to different forms according to their authority. anyways i can do it with this help. you made me to feel simple.
Krishna Rajput SinghPosted Sep 28, 2014, 2:47 AM
once again thank for more views and downloads all programmer
Krishna Rajput SinghPosted Sep 19, 2014, 6:32 AM
i think this Article is helpful for u thnks fr more view and Downloads