C# Login Window

Login Window In C#

                                                                                                                                         

In This C# Tutorial We Will See How To Create A Login Form And Hide The Login Form And Show Another Form Using CSharp Programming Language And MySQL Database.
-

Source Code :

using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Csharp_And_MySQL
{
    public partial class Login_Form_3 : Form
    {
        public Login_Form_3()
        {
            InitializeComponent();
        }
        MySqlConnection connection = new MySqlConnection("datasource=localhost;port=3306;Initial Catalog='test';username=root;password="); 

        MySqlDataAdapter adapter;

        DataTable table = new DataTable();

        private void BTN_CANCEL_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void BTN_LOGIN_Click(object sender, EventArgs e)
        {
            adapter = new MySqlDataAdapter("SELECT `username`, `password` FROM `users` WHERE `username` = '" + textBox_Username.Text + "' AND `password` = '" + textBox_Password.Text + "'", connection);

            adapter.Fill(table);

            if(table.Rows.Count <= 0)
            {
                MessageBox.Show("Invalid Username Or Password");
            }

            else
            {
                this.Hide();
                Csharp_insert_image_into_mysql_database f = new Csharp_insert_image_into_mysql_database();
                f.FormClosed += (s, args) => this.Close();
                f.Show();
            }

        }
     
    }

}
=> OutPut :

c# login window

c# login form




Share this

Related Posts

Previous
Next Post »