高手进!ASP.NET编程问题:登录界面出了点小问题
using System;using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string strConn = @"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\ASP.NET练习\个人网站\App_Data\user.mdf;Integrated Security=True;User Instance=True";
SqlConnection conn = new SqlConnection(strConn);
string strCmd="select * from user_info where username='"+TextBox1.Text+"'";
SqlCommand comm=new SqlCommand(strCmd,conn);
conn.Open();
SqlDataReader reader=comm.ExecuteReader();
if(reader.HasRows)
{
reader.Read();
if(reader["passwords"].ToString()==TextBox2.Text)
{
/*Session["user"]=TextBox1.Text;
Session["status"]=reader["status"].ToString();*/
Response.Redirect("index.aspx")
}
else
{
wrongmsg.Text = "密码错误!请检查后输入。";
Response.Redirect("login.aspx")
}
}
else
{
wrongmsg.Text = "用户不存在!请检查后再输入。";
Response.Redirect("login.aspx")
}
}
}
这是后台验证的代码,我数据库里建立了一个 username和passwords字段加入一条数据是username:test password:abc123;网页有一个Lable名字是wrongmsg...运行了不能正常载入到index,也不能正常返回错误信息..一直停留在原页面;
补充:不好意思..调试出错误了.上面的代码没有错误..是aspx页面的头声明出错了
追问:什么情况...这位大神代码就在上面贴着..难道你没有发现是C#??这个让老夫如何是好...呵呵