各位,帮我看看
private void Button1_Click(object sender, System.EventArgs e)
{
SqlConnection con=db.createConnection();
con.Open();
SqlCommand cmd=new SqlCommand("select * from admintable",con);
SqlDataReader sdr=cmd.ExecuteReader();
string user="";
string password=""; if(sdr.Read())
{
user=sdr[0].ToString();
password=sdr[1].ToString();
}
if(this.Label1.Text==user&&this.Label2.Text==password)
{ Response.Redirect("main.aspx");
}
else
{
Response.Write("登录失败!");
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
SqlConnection con=db.createConnection();
con.Open();
SqlCommand cmd=new SqlCommand("select * from admintable",con);
SqlDataReader sdr=cmd.ExecuteReader();
string user="";
string password=""; if(sdr.Read())
{
user=sdr[0].ToString();
password=sdr[1].ToString();
}
if(this.Label1.Text==user&&this.Label2.Text==password)
{ Response.Redirect("main.aspx");
}
else
{
Response.Write("登录失败!");
}
}
换成TextBox试试
{ Response.Redirect("main.aspx");
}
//注意,说得是这里
{
string user= this.用户名TextBox.Text;
string password=this.密码TextBox.Text;SqlConnection con=db.createConnection();
con.Open();
SqlCommand cmd=new SqlCommand("select * from admintable where 用户名字段='"+user+"' and 密码字段='"+password+"'",con);SqlDataReader sdr=cmd.ExecuteReader();if(sdr.Read())
{
sdr.Close();
Response.Redirect("main.aspx");
}
else
{
Response.Write("用户名或密码错误,登录失败!");
sdr.Close();
}}