0
public partial class Account_Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LoginButton_Click(object sender, EventArgs e)
{
string UName = UserName.Text.Trim();
string pwd = Password.Text;
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Project_DBConnectionString"].ConnectionString))
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "SELECT id, username, password, email FROM [Employee] WHERE username = '" + UName + "' and password = ' " + pwd + "' ";
con.Open();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(dt);
if (dt.Rows.Count > 0)
{
Session.Add("UserID", dt.Rows[0][0].ToString());
Session.Add("UserName", dt.Rows[0][1].ToString());
Session.Add("Password", dt.Rows[0][2].ToString());
Session.Add("Email", dt.Rows[0][3].ToString());
if (dt.Rows[0][1].ToString() == "admin")
{
Response.Redirect("~/Admin/Default.aspx", false);
}
else
{
Response.Redirect("~/MemberPages/Default.aspx", false);
}
}
else
{
FailureText.Text = "Invalid Username and Password";
}
}
}
}
它給我一個UserName.Text和password.Text錯誤。它說這在這種情況下不存在。在asp.net中登錄頁面錯誤
我不知道這是怎麼回事。
註冊頁面也出現同樣的問題。
顯示你的'Account_Login.aspx' – Roar
請顯示你的標記部分,你在哪裏添加了用戶名和密碼的文本框 –