各位,帮我看看
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("登录失败!");
}
}

解决方案 »

  1.   

    你在Label上输入用户名和密码阿,厉害
    换成TextBox试试
      

  2.   

    if(this.Label1.Text==user&&this.Label2.Text==password)
    { Response.Redirect("main.aspx");
    }
    //注意,说得是这里
      

  3.   

    sql语句有问题select * from admintable where 用户名字段='"+user+"' and 密码字段='"+password+"'另外代码应该改成这样private void Button1_Click(object sender, System.EventArgs e)
    {
    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();
    }}
      

  4.   

    改成了TextBox,还是不行啊!!调试的时候说:SqlCommand cmd=new SqlCommand("select * from admintable",con)有问题,要怎么搞啊