So I know this is a often asked question but I want to check if the username is already taken in the database using c#. I tried this:
MySqlCommand cmd2 = new MySqlCommand("SELECT * FROM tablename WHERE(name = '" + tb1.Text + "');");
cmd2.Connection = connect;
connect.Open();
string unt = "";
try
{
    MySqlDataReader dr;
    dr = cmd.ExecuteReader();
    while (dr.Read())
    {
        unt= dr.GetString("name");
    }
    dr.Close();
}
catch (Exception ex)
{
    errorbox.Content = ex.Message;
}
finally
{
    connect.Close();
}
if(unt == "" || unt == "0") {
    continuel = false;
    tb2.Text = "User " +tb1.Text+ " doesn't exist!";
    Popup1.IsOpen = true;
}
Its a WPF project and the variable 'continuel' is set to true by default. The code doesn't recognize if a user doesn't exist.