当前上下文中不存在名称“UserName"和“password”。 10
我的Login.aspx.cs代码如下:usingSystem;usingSystem.Collections;usingSystem.Configuration;usi...
我的Login.aspx.cs代码如下:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Xml.Linq;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button_Click(object sender, EventArgs e)
{
string strConnection = "SERVER=(local);DATABASE=HX1;UID=sa;PWD=password1.";
System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(strConnection);
string strSql = "SELECT * FROM User WHERE U_Name='" + UserName.Text + "' and U_Pwd='" + Password.Text + "'";
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(strSql, cn);
System.Data.DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
Session["UserName"] = dt.Rows[0]["u_name"].ToString();
Session["Message"] = "登录成功!";
Response.Redirect("default.aspx");
}
else
{
Session["Message"] = "登录失败。请重新登录。";
Response.Redirect("Login.aspx");
}
}
}
用的是VS 2008,总是报错,我是初学者,那两个Textbox的ID是UserName和password啊,怎么读不到数据呢?
请教高人,具体错在什么地方,我应如何做,越详细越好。 展开
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Xml.Linq;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button_Click(object sender, EventArgs e)
{
string strConnection = "SERVER=(local);DATABASE=HX1;UID=sa;PWD=password1.";
System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(strConnection);
string strSql = "SELECT * FROM User WHERE U_Name='" + UserName.Text + "' and U_Pwd='" + Password.Text + "'";
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(strSql, cn);
System.Data.DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
Session["UserName"] = dt.Rows[0]["u_name"].ToString();
Session["Message"] = "登录成功!";
Response.Redirect("default.aspx");
}
else
{
Session["Message"] = "登录失败。请重新登录。";
Response.Redirect("Login.aspx");
}
}
}
用的是VS 2008,总是报错,我是初学者,那两个Textbox的ID是UserName和password啊,怎么读不到数据呢?
请教高人,具体错在什么地方,我应如何做,越详细越好。 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询