在写ASP.NET登录页面 的时候,登录不成功。
user.UserName = tbName.Text.Trim(); 这里已经填了,像user.UserName="daaa".但是 UserDao里面userName值 为空。
自己调试过,发现 class UserDao里面的user.UserName,与其他相应的值为空。我在想是不函数调用问题?
需要写反射吗??namespace ArticleCMS.Entity
{
public class User
{
private int userId; public int UserId
{
get { return userId; }
set { userId = value; }
}
private string userName; public string UserName
{
get { return userName; }
set { userName = value; }
}
private string userPassword; public string UserPassword
{
get { return userPassword; }
set { userPassword = value; }
}
private int userPower; public int UserPower
{
get { return userPower; }
set { userPower = value; }
}
}
}namespace ArticleCMS.Dao
{
public class UserDao
{
/// <summary>
///检查用户是否存在
/// </summary>
/// <returns>如果存在返回100,否则返回-100</returns>
public int UserExist()
{
SqlParameter[] para = new SqlParameter[3];
para[0] = new SqlParameter("@UserName", SqlDbType.VarChar, 20);
para[0].Value = user.UserName;
para[1] = new SqlParameter("@UserPassword", SqlDbType.VarChar, 20);
para[1].Value = user.UserPassword;
para[2] = new SqlParameter("@ReturnValue", SqlDbType.Int);
para[2].Direction = ParameterDirection.ReturnValue; datastore.Updata("UserExists", para);
return (int)para[2].Value; }
namespace ArticleCMS
{
public partial class Login : DB.ValidateBase
{
Dao.UserDao userdao = new ArticleCMS.Dao.UserDao();
Entity.User user = new ArticleCMS.Entity.User(); protected void Page_Load(object sender, EventArgs e)
{
} protected void LoginSubmit_Click(object sender, EventArgs e)
{ user.UserName = tbName.Text.Trim();
user.UserPassword = tbPassword.Text.Trim();
if (tbRegister.Text == base.strValidate)
{
int isExist= userdao.UserExist();
if (isExist == 100)
{ SqlDataReader dr = userdao.UserIDPower();
Session["UserId"] = dr["UserId"].ToString();
Session["UserPower"] = dr["UserPower"].ToString();
Response.Redirect("http://www.baidu.com");
}
else
{
Response.Write("<script>alert('您的登录有误,请核对后再重新登录!');location='javascript:history.go(-1)';</script>");
}
}
else
{
Response.Write("<script>alert('请正确输入验证码!');location='javascript:history.go(-1)';</script>");
}
}
}
}
user.UserName = tbName.Text.Trim(); 这里已经填了,像user.UserName="daaa".但是 UserDao里面userName值 为空。
自己调试过,发现 class UserDao里面的user.UserName,与其他相应的值为空。我在想是不函数调用问题?
需要写反射吗??namespace ArticleCMS.Entity
{
public class User
{
private int userId; public int UserId
{
get { return userId; }
set { userId = value; }
}
private string userName; public string UserName
{
get { return userName; }
set { userName = value; }
}
private string userPassword; public string UserPassword
{
get { return userPassword; }
set { userPassword = value; }
}
private int userPower; public int UserPower
{
get { return userPower; }
set { userPower = value; }
}
}
}namespace ArticleCMS.Dao
{
public class UserDao
{
/// <summary>
///检查用户是否存在
/// </summary>
/// <returns>如果存在返回100,否则返回-100</returns>
public int UserExist()
{
SqlParameter[] para = new SqlParameter[3];
para[0] = new SqlParameter("@UserName", SqlDbType.VarChar, 20);
para[0].Value = user.UserName;
para[1] = new SqlParameter("@UserPassword", SqlDbType.VarChar, 20);
para[1].Value = user.UserPassword;
para[2] = new SqlParameter("@ReturnValue", SqlDbType.Int);
para[2].Direction = ParameterDirection.ReturnValue; datastore.Updata("UserExists", para);
return (int)para[2].Value; }
namespace ArticleCMS
{
public partial class Login : DB.ValidateBase
{
Dao.UserDao userdao = new ArticleCMS.Dao.UserDao();
Entity.User user = new ArticleCMS.Entity.User(); protected void Page_Load(object sender, EventArgs e)
{
} protected void LoginSubmit_Click(object sender, EventArgs e)
{ user.UserName = tbName.Text.Trim();
user.UserPassword = tbPassword.Text.Trim();
if (tbRegister.Text == base.strValidate)
{
int isExist= userdao.UserExist();
if (isExist == 100)
{ SqlDataReader dr = userdao.UserIDPower();
Session["UserId"] = dr["UserId"].ToString();
Session["UserPower"] = dr["UserPower"].ToString();
Response.Redirect("http://www.baidu.com");
}
else
{
Response.Write("<script>alert('您的登录有误,请核对后再重新登录!');location='javascript:history.go(-1)';</script>");
}
}
else
{
Response.Write("<script>alert('请正确输入验证码!');location='javascript:history.go(-1)';</script>");
}
}
}
}
解决方案 »
- asp.net页面中的文本框里如何实现ctrl+z的撤销命令呢?
- 求解。高手速进,马上结贴~
- gredview与checkbox组合标题显示的问题
- 存储过程中用select top 变量 的问题
- 读取多张图片,不刷新切换图片
- asp.net2.0, c#,Button,点击button后传递参数打开另一页面
- 如何将DataSet 的数据全部写入到数据库中啊?
- 如何保留iframe页中的状态
- 初学者---简单的dropdownlist问题,麻烦各位帮我看看..
- 发布异常--数据库读取失败
- asp.net中 前台js怎样去调用后台已经有的方法,不要放Button或者其他别的
- 请高手帮帮忙DataList嵌套问题
执行UserExists看看效果
是否要用什么函数调用 呢??
public int Updata(string proc, SqlParameter[] para)
{
if (conn != null)
{
conn.Close();
}
conn.Open();
SqlCommand cmd = Command(proc, para);
int nI;
try
{
nI = cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw (ex);
}
finally
{
cmd.Dispose();
conn.Close();
}
return nI;
}
public SqlCommand Command(string proc, SqlParameter[] para)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = proc;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn; if (para != null)
{
foreach (SqlParameter pa in para)
{
cmd.Parameters.Add(pa);
}
}
return cmd;
}
cmd.Connection = conn;
cmd.CommandText = strSqlOrProcedure;
cmd.CommandType = cmdType;
if (Params != null && Values != null && Params.Length == Values.Length) {
for (int i = 0; i < Params.Length; i++) {
SqlParameter sp = new SqlParameter();
sp.ParameterName = Params[i];
sp.Value = Values[i];
sp.Direction = ParameterDirection.Input;
cmd.Parameters.Add(sp);
}
}
Params = null;
Values = null;
}
public int UserExist(User user)
{
SqlParameter[] para = new SqlParameter[3];
para[0] = new SqlParameter("@UserName", SqlDbType.VarChar, 20);
para[0].Value = user.UserName;
para[1] = new SqlParameter("@UserPassword", SqlDbType.VarChar, 20);
para[1].Value = user.UserPassword;
para[2] = new SqlParameter("@ReturnValue", SqlDbType.Int);
para[2].Direction = ParameterDirection.ReturnValue; datastore.Updata("UserExists", para);
return (int)para[2].Value; }
int isExist= userdao.UserExist();
int isExist= userdao.UserExist(user);