本人一初学者,问题比较幼稚,希望大家给以解答.
只是一个留言板,做好注册和登陆界面,打算转到留言板时怎么也转不过去,代码如下:
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();
} }
只是一个留言板,做好注册和登陆界面,打算转到留言板时怎么也转不过去,代码如下:
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();
} }
在这句上下断点看能否执行这句还有,判断用户名不存在不应该使用异常来判断,可以使用ds.Tables["mytable"].Rows.Count<=0来判断
catch(Exception e)
{
throw e;
//Label1.Text="sorry,你输入的用户名不存在";
}
再断点调试,看看报什么错。估计是messages.aspx文件目录不对