这是问题所在:
如果值与TextBox2.Text
and in相同Label2.Text
,我想这样做,我不会被重定向到下一页,而是会要求我输入不同的文本。这是我的代码:
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd = new SqlCommand("SELECT Question FROM Animals WHERE Question = @Question", con);
cmd.Parameters.AddWithValue("@Question", Label2.Text);
cmd.ExecuteNonQuery();
dr = cmd.ExecuteReader();
if (dr.Read())
{
Response.Write("Enter different question");
}
else
{
if(dr[0].ToString() != TextBox2.Text)
Session["question"] = Label2.Text;
Session["Animal3"] = TextBox1.Text;
Session["Question2"] = TextBox2.Text;
Session["Animal2"] = Label3.Text;
Session["Animal"] = Label4.Text;
Response.Redirect("~/StartGame2.aspx");
}