Windows Forms Application Login Demo with MySQL Connection in C# .NET

After testing out Java for a couple of weeks, this weekend I decided to try out .NET. I am a big fan of web applications but recently I’ve taken an interest towards Java and Windows Forms Applications. So, the first thing that came to my attention was the Windows Application Forms in C#.

So, basically I’ve used Visual Studio 2012 and for database I’ve used EasyPHP Dev Server because MySQL is my most favorite database.

GUI Design

For GUI design, I kept it simple – some panels, labels and textboxes along with buttons.

Windows Forms Application

So, that cares of the simple GUI.

MySQL Database Connection

Before making the MySQL database connection, you need to download MySQL .NET Connector which you can download from here. After downloading the connector for the .NET and MONO platform, you need to extract it. Then you will need to add these two files – and mysql.web.dll as reference in your project. These two files are basically ADO .NET MySQL Driver.

Windows Forms Application

After the addition of these two references you can write the code. The most important function in Login is that of the “Submit” button. So, here’s the simple code that I used.

So from above the name of the MySQL database is netdemo and the name of the table is login.

Validation and Output

For a little added security, I’ve added a validation parameter. If both or one of the textbox is empty while submitting the form, it will display a error message like the one below.

Windows Forms Application

For the correct username and password, it will show a message box of “Correct Login Credentials” and for an incorrect combo it will display a message box of “Incorrect Login Credentials”.

Windows Forms Application

So, that’s it for this one. Stay tuned for more Application Development Tutorials.

Author: Lahaul Seth

A programmer and a web developer, he is the founder of Lion Blogger. His main hobbies are web design & development and providing writing services to clients.

Share This Post On

Pin It on Pinterest

Share This