MySQL Login Form C#.

MySql Download Link – https://dev.mysql.com/downloads/connector/net/

Download Complete Code : Click Here

using System;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace Login_Mysql
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void exit_btn_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void login_btn_Click(object sender, EventArgs e)
        {
            string cs = @"server=localhost;userid=root;password=123456;database=test";
            var con = new MySqlConnection(cs);

            try
            {
                con.Open();
                string stm = "select name,password from log WHERE name =@Name AND password =@Password";
                var cmd = new MySqlCommand(stm, con);

                cmd.Parameters.AddWithValue("@Name", username_txt.Text);
                cmd.Parameters.AddWithValue("@Password", pwd_txt.Text);
                cmd.ExecuteReader();
                main_form();
            }
            catch (Exception ex)
            {
                Console.WriteLine("login failed");
            }
            con.Close();
        }

        private void main_form()
        {
            this.Hide();
            main frm = new main();
            frm.ShowDialog();
            this.Close();
        }
    }
}