为什么没有跳转到相应的页面去,能帮看一下代码 吗
private void Button1_Click(object sender, System.EventArgs e)
{
if(Authenticate(TextBox1.Text,TextBox2.Text ))
{
Server.Transfer("sx_teacher_nfo/teacher.aspx");}
else
{
}
}private bool Authenticate(string username, string password)
{SqlConnection conn = new SqlConnection ("server=localhost;" +"database=sx;Trusted_Connection=Yes");
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "sx_login";SqlParameter ParameterUserName = new SqlParameter("@UserName",SqlDbType.VarChar,20);
ParameterUserName.Value = username;
cmd.Parameters.Add(ParameterUserName);SqlParameter ParameterPassword = new SqlParameter("@Password",SqlDbType.VarChar,50);
ParameterPassword.Value = password;
cmd.Parameters.Add(ParameterPassword);
 
int usercount = Convert.ToInt16(cmd.ExecuteScalar());
if(usercount>0)
{
return true;
}
else
{
return false;
}
conn.Close();
}

解决方案 »

  1.   

    连接字符串中的Trusted_Connection=Yes什么意思?
    偶没用过
    而且根据你调试的看能不能执行到Server.Transfer("sx_teacher_nfo/teacher.aspx");语句
      

  2.   

    Server.Transfer doesn't change the url in the browser, try the following to make sure your code works first
    private void Button1_Click(object sender, System.EventArgs e)
    {
    if(Authenticate(TextBox1.Text,TextBox2.Text ))
    {
     Response.Write("authenticated");}
    else
    {
      Response.Write("not authenticated");
    }
    }also you didn't close the connection properly, should doint usercount = Convert.ToInt16(cmd.ExecuteScalar());
    conn.Close();
    if(usercount>0)
    {
    return true;
    }
    else
    {
    return false;
    }