Sunday, September 30, 2018

Login from database in Windows Application C# Code

Login from database in Windows Application C# Code


private void button1_Click(object sender, EventArgs e)
        {
            // Validation for User Name
            if (txtUserName.Text.Trim() == "")
            {
                MessageBox.Show("Please Enter User Name");
                txtUserName.Focus();

                return;

            }
            // Validation for Password
            if (txtPassword.Text.Trim() == "")
            {
                MessageBox.Show("Please Enter Password");
                txtPassword.Focus();

                return;

            }

            SqlCommand cmd = new SqlCommand("select * from Login where User_Id ='" + txtUserName.Text + "'and Password='" + txtPassword.Text + "'", con);

            SqlDataAdapter dr = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            dr.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                this.Hide();
                Welcome wel = new Welcome();
                wel.Show();

            }
            else
            {

                MessageBox.Show(" Please enter correct User Name and password");


            }

           
        }

No comments:

Post a Comment