RunCodesRunCodes - Programming & Tech

  • Home
  • C#.NET
  • PHP
  • JAVA
  • Python
  • ASP.NET
  • VB.NET
  • Android
  • C
  • Tech
    • Tech News
  • Patreoner
RunCodes
  • Home
  • Programming
  • C#.NET
  • How to Create Login Window in C# using SQL Server Database in Visual Studio?
C#.NET

How to Create Login Window in C# using SQL Server Database in Visual Studio?

By Er. Ran Bahadur B.K. Last updated Aug 15, 2021
1 4,596
Share

Hello Everyone, If you are planning to study C# programming for your project or if you are interested to learn C# Programming, Then, i am going to write one article about the C# related project (a small project/application) using Window Form Application in Visual Studio which is the very basic but very important guideline for you. But this will be very important project for you if you do not try before. As you all know C# is an Event Driven Programming Language this features enable us to drag and drop some controls like button, textbox, labels etc directly rather than writing code for them and this actually save your time when you are programming and also make us easy to program. This project will show you how to drag and drop controls from tools into your window form and how to connect your application to database which is the important and most basic knowledge you should know when you are making a complex system using C#.

So, i am going to give you demonstration about how to create login window using C# which is based on windows form application through the video. So, please do watch following video for this little but very important project.

First of all you need to have Visual Studio and SQL Server Studio. you all can download these software from microsoft official website.

SQL Server: From Here

Visual Studio: From Here

STEPS:

1. Open your visual studio of any version and then go to file new and then click on project. Then new window will appear and from the left pane select visual c#. under visual c# select window and then select window form application from the middle pane and give the name of your project and click ok.

2. Drag and drop two label, two textbox and one button from the toolbox and change the text and name of these control from the properties of these controls.

3. Now from the left pane select server explorer and right click on data connection and click on add connection. After clicking on add connection new window will appear and you will see the Data Source option and Database file name (new or existing); set the Data Source to Microsoft SQL Server Database File(SqlClient ) and give any name in the database file name section and then click ok, new window will appear as below:

Then click yes, after clicking yes, server explorer will look like the following one:

4. Then right click on table>Add new Table, add username and password in the name section and choose the data type and then click on the update icon.

you can also change the name of the table from the SQL Command shown just below the this table and then you should click on update button.

5. Now select you database in my case testlogin.mdf from the server explorer and go to properties, from the properties window copy the connection string.

6. Now you need to add one namespace as:

using System.Data.sqlclient;

7. Then go to the design section of the login window and double click on the button and write following code inside that button.

Note: change the connection string and SQL Statement (Table name and database name) based on your specification.

SqlConnection conn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\RANBAH~1\Documents\testlogin.mdf;Integrated Security=True;Connect Timeout=30");
            SqlDataAdapter sda = new SqlDataAdapter("select count(*) from login where username ='" + textBox1.Text + "' and password='" + textBox2.Text + "'", conn);
            DataTable dt = new DataTable();
            sda.Fill(dt);
            if (dt.Rows[0][0].ToString() == "1")
            {
                this.Hide();
                Main mm = new Main();
                mm.Show();
            }
            else
            {
                MessageBox.Show("please enter correct username and password", "alert", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

Watch the video for the full guideline!

 

 

Continue Reading
c# code for login formc# login formc# login form exampleC# Login Windowhow to connect database to c #How to create c# login form?how to create c# login window?how to create login form in c# using sql serverhow to create login form in c# with databasehow to create login form in c# without databasehow to create login form in visual studiohow to make login window in c#RanBKSimple Windows Form Login Application in C#TechSupportNepvery simple project in c#
1 4,596
Share FacebookTwitterReddItWhatsAppPinterestEmail
Er. Ran Bahadur B.K.60 posts 56 comments

Ran Bahadur B.K. is the owner of TechSupportNep who is working with the aim of providing the quality Technology content. He is creating Tech and Programming videos, you can see all them in his YouTube Channel(https://www.youtube.com/TechSupportNep). He is also working with some company.

Prev Post

How to Create Login Form in PHP using Dreamweaver and MySQL Database?[With Source Code]

Next Post

How to Show Alert Dialog Box in Android?

You might also like More from author
C#.NET

How to Send an Email using C#.NET?

C#.NET

How to Send Free SMS Using C#.NET? [With Source Code]

C#.NET

Create Simple Login Form in C#.NET Without Connecting to Database [With Source Code]

Show Comments (1)
Help Needed

This website is free of annoying ads. We want to keep it like this. You can help with your support:

Donate!

The need for Support! Why to Support?

If you need your own website? contact me!
erranbahadurbk
Fiverr
Seller
Hello there,This is me Ran Bahadur B.K., A graduated computer engineer. I have 3+ years of work experience in wordpress design and development. I have strong knowledge of HTML, CSS and PHP which are the three ingredients of web development. Currently i am working with the software company so i also have experience in desktop apps and mobile apps development.

Latest

Python

How to Create Login Application in Python using SQLite Database?

How to use View Binding in Android?

Windows 10 Build 1909 Features that you should know.

How to Create a Complete Login and Forgot Password System in java ?

Prev Next 1 of 15
  • About us
  • Contact us
  • Privacy Policy
  • Disclaimer
© 2022 All Rights Reserved.
Website By: Ran Bahadur B.K.