做了个登陆界面,现在也不跳转也不报错,是什么原因
protected void btn_log_Click(object sender, EventArgs e)
{
string id = txt_id.Text;
string pwd = txt_pwd.Text;
string connstr = "Data Source=WIN-BO2B3PISMP6;database=test;Initial Catalog=test;Integrated Security=True";
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
string selectstr = "select * from student where stu_id ='id' and stu_pwd=pwd'";
//LinkDatabase link = new LinkDatabase();
//int n = link.code_Id(selectstr);
//if (n > 0)
//{ Response.Redirect("index.aspx"); }
SqlCommand cmd = new SqlCommand(selectstr, conn);
SqlDataReader data = cmd.ExecuteReader();
if (data.Read())
{
string sid = data.GetString(1);
string spw = data.GetString(2);
if (sid == id & spw == pwd)
{
Response.Redirect("index.aspx");
}
else
{
wrongmessage.Text = "Incorrect user name or password.";
wrongmessage.Visible = true;
}
}
conn.Close();
------解决方案--------------------string selectstr = "select * from student where stu_id ='id' and stu_pwd=pwd'";
=>
string selectstr =string.Format( "select * from student where stu_id ='{0}' and stu_pwd='{1}'",id,pwd);
------解决方案-------------------- if (data.Read())
{
......
}else{
Response.Write("数据未取到");
}