閱讀的問題:ASP.NET從數據庫
我想讓如果值相同那就是TextBox2.Text
和Label2.Text
,我不會重定向到下一個頁面,而是我會要求輸入不同text.Here是我的代碼:
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");
}
不清楚你想做什麼。 – 2013-05-12 13:35:45
什麼是'TextBox2','Label2'? ,請詳細解釋 – 2013-05-12 13:37:15
如果textbox2中的數據等於label2(它已經存儲在數據庫中),它會抱怨它,並要求輸入不同的數據。 – 2013-05-12 13:38:22