Okay so I'm basically trying to verify whether the username being entered is a duplicate but there's a problem in the string comparison inside the while loop
I tried using a temp label to verify that the values are being extracted correctly.
protected void BtnConfirmSignup_Click(object sender, EventArgs e)
{
int f = 0;
SqlConnection con = new SqlConnection("Data Source=(localdb)\\MSSQLlocalDB;Initial Catalog=traveller;Integrated Security=True;Pooling=False");
SqlCommand cmd;
SqlDataReader read;
/*DEBUG: Prevent duplicate usernames*/
try
{
Session["user"] = TxtUsrName.Text;
Session["pass"] = TxtPsswd.Text;
Session["email"] = TxtEmail.Text;
//Label6.Text = "Faf";
// if ((Label6.Text).Equals(TxtUsrName.Text))
//{
// Label6.Text = "dafuqqqq";
//}
//{
// Label6.Text = "wtf";
// Label6.Text = TxtUsrName.Text;
//}
cmd = new SqlCommand("select Name from Useriden", con);
con.Open();
read = cmd.ExecuteReader();
while (read.Read())
{
Label6.Text = read["Name"].ToString();
Label1.Text = "aaa";
//Label6.Text = "Faf";
if ((Label6.Text).Equals(TxtUsrName.Text))
{
f = 1;
//Label6.Text = "Duplicate Username";
break;
}
}
if (f == 1)
{
Label6.Text = "Duplicate Username";
}
else if (f == 0)
{
Response.Redirect("SignUpNext.aspx");
}
}
catch (Exception ex) {
LabelUserName.Visible = true;
LabelUserName.Text = ex.Message;
con.Close();
ViewState["Caption"]=ex.Message;
}
}
Expected: I'm entering a duplicate name so it should the change the text of the label to Duplicate Username but it instead navigates to the next page/The value of f never changes.
Aucun commentaire:
Enregistrer un commentaire