lundi 19 octobre 2020

Create login page using C# Windows application - Login button not working [closed]

I need to create a login page as below: Home Page of the program. For the "Login" button I wrote code as below. When I am running the following part is not working

if (dt.Rows[0]["TypeUser"].ToString() == cmbItem)
        {
            MessageBox.Show("You are login as " , cmbItem);
            Dashboard das = new Dashboard();
            das.Show();
        }  

The whole code for the button as below

private void button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("Data Source=DESKTOP-5APD03B;Initial Catalog=login;Integrated Security=True");
        SqlCommand cmd = new SqlCommand("Select * from login where Username ='" + username.Text + "' and Password = '" + password.Text + "'", con);
        SqlDataAdapter sda = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        sda.Fill(dt);
        string cmbItem = typeuser.SelectedItem.ToString();
        
        if (dt.Rows[0]["TypeUser"].ToString() == cmbItem)
        {
            MessageBox.Show("You are login as " , cmbItem);
            Dashboard das = new Dashboard();
            das.Show();
        }                             
        
        else
        {
            MessageBox.Show("Error");
        }
    }

Aucun commentaire:

Enregistrer un commentaire