本人一初学者,问题比较幼稚,希望大家给以解答.
只是一个留言板,做好注册和登陆界面,打算转到留言板时怎么也转不过去,代码如下:
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = db.CreateConnection();
        con.Open();
        string strsql = "select upass from login where uname='" + this.TextBox1.Text + "'";
        SqlCommand cmd=new SqlCommand(strsql,con);
        //创建一个数据集
        DataSet ds = new DataSet();
        //创建一个适配器
        SqlDataAdapter da = new SqlDataAdapter(strsql, con);
        //填充数据集
        da.Fill(ds, "mytable");
        try
        {
            //判断密码文本框是否和数据集的密码相同
            if (this.TextBox2.Text == ds.Tables[0].Rows[0].ItemArray[0].ToString().Trim())
            {
                string curuser = this.TextBox1.Text;
                Session["uname"] = this.TextBox1.Text.ToString();
                string aa = this.TextBox3.Text.ToString();
                if (aa == Convert.ToString(Session["Image"]))
                {
                    Response.Redirect("messages.aspx");
                }
                else
                {
                    Response.Write("<script>alert('验证码错误')</script>");
                }
            }
             else
             {
                  Label1.Text="sorry,用户名或密码错误";
             }
          }
          catch
          {
              Label1.Text="sorry,你输入的用户名不存在";
          }
        con.Close();
        }    }

解决方案 »

  1.   

    单步跟踪一下.报什么错了?Response.Redirect("messages.aspx");这个没有错。
      

  2.   

    Response.Redirect("messages.aspx"); 
    在这句上下断点看能否执行这句还有,判断用户名不存在不应该使用异常来判断,可以使用ds.Tables["mytable"].Rows.Count<=0来判断
      

  3.   

    怎么用断点看是否能执行???我在上下都加了断点,运行到Response.Redirect("messages.aspx");再F10就到了catch那里,请问是什么原因???
      

  4.   

    把catch改一下
    catch(Exception e)
    {
      throw e;
      //Label1.Text="sorry,你输入的用户名不存在"; 
    }
    再断点调试,看看报什么错。估计是messages.aspx文件目录不对
      

  5.   

    可能是messages.aspx不存在(写错没有??)或者路径不在同一目录
      

  6.   

    试过了,出现了"不能在此范围内声明名为“e”的局部变量,因为这样会使“e”具有不同的含义,而它已在“父级或当前”范围中表示其他内容了""捕获或抛弃的类型必须从 System.Exception 派生"两个毛病.messages和login都在根目录下messages调试也没有报错...貌似真的解决不了了么????