使用命名空间出现个错误 大侠请赐教 说的详细的给100分

huzilong4460072 2008-12-15 01:28:04
在命名空间BussinessLogicLayer里的User方法代码如下:
using MyChatRoom.DataAccessLayer;
namespace MyChatRoom.BussinessLoginLayer
{

public class User
{
private string _userName;
private string _passWord;
private bool _Exist;
/// <summary>
/// 根据参数userName,获取用户详细信息
/// </summary>
public void LoadData(string userName)
{
Database db = new Database(); //实例化一个Database类
string Sql="select * from [User] where UserName='"+userName+"'";
DataRow dr = db.GetDataRow(Sql); //利用Database类里的GetDataRow方法查询数据库
if (dr != null)
{
this._userName = dr["UserName"].ToString();
this._passWord = dr["PassWord"].ToString();
this._Exist = true;
}
else
this._Exist = false;
}
public void Add(string userName, string passWord)
{
Database db = new Database(); //实例化一个Database类
string Sql = "insert [User] values('"+userName+"','"+passWord+"')";
db.ExecuteSQL(Sql); //利用Database类里的ExecuteSQL方法插入数据
}
}
用户界面里Button_onclick的代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
string userName = txtUserName.Text.Trim();
string passWord = txtPassWord.Text.Trim();
MyChatRoom.BussinessLoginLayer.User user = new User();
user.LoadData(userName); //获取用户信息
if (user.Exist)
{
Response.Redirect("Main.aspx");
}
}

这里有个错误 user.Exist //在实例化的user里找不到的
大侠教教我 要在User方法里怎么修改阿?
...全文
109 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
zilong4460072 2008-12-15
  • 打赏
  • 举报
回复
1楼的很正确阿
但是前提是要把 private改成public 在button_click里才可以引用
yajun_snow 2008-12-15
  • 打赏
  • 举报
回复
public bool Exist
{
get{return _Exist;}
set{_Exist= value;}
}
路人乙e 2008-12-15
  • 打赏
  • 举报
回复
User类中少一属性:Exist

public string Exist
{
get{ return _Exist; }
}
gang027 2008-12-15
  • 打赏
  • 举报
回复
帮顶, 试试1楼的
zhnzzy 2008-12-15
  • 打赏
  • 举报
回复
你只能感应,断点点的出来吗?
jiang_jiajia10 2008-12-15
  • 打赏
  • 举报
回复

protected void Button1_Click(object sender, EventArgs e)
{
string userName = txtUserName.Text.Trim();
string passWord = txtPassWord.Text.Trim();
MyChatRoom.BussinessLoginLayer.User user = new User();
user.LoadData(userName); //获取用户信息
if(user.Exist) //如果是老用户
{
if(user.Password==password) {
Response.Redirect("Main.aspx");
}
else {
Response.Write("<Script Language=JavaScript>alert(\"验证失败,请重新登录!\")</Script>");
}
}
}


最好再验证一下密码是否正确
HDNGO 2008-12-15
  • 打赏
  • 举报
回复
public bool Exist
{
get
{
return this._exist;
}
}

jiang_jiajia10 2008-12-15
  • 打赏
  • 举报
回复
还有其他的

public string UserName
{
set
{
this._userName=value;
}
get
{
return this._userName;
}
}
public string Password
{
set
{
this._password=value;
}
get
{
return this._password;
}
}
jiang_jiajia10 2008-12-15
  • 打赏
  • 举报
回复

public bool Exist
{
get
{
return this._exist;
}
}

加上就能找到了。
yyq136 2008-12-15
  • 打赏
  • 举报
回复
这里有个错误 user.Exist //在实例化的user里找不到的
你的程序中并没有加Exist属性。只是设置了一个_Exist变量
在User类中加一个
Public bool Exist
{
get
{
return _Exist;
}
}
即可
ErosSignum 2008-12-15
  • 打赏
  • 举报
回复
晕,没你们抢的快啊
gongsun 2008-12-15
  • 打赏
  • 举报
回复
private string _userName;
private string _passWord;
private bool _Exist;

这些是私有成员变量 你重构给类对应,加上属性就可以用 user.Exist
zjybushiren88888 2008-12-15
  • 打赏
  • 举报
回复
帮顶, 试试1楼的
ErosSignum 2008-12-15
  • 打赏
  • 举报
回复
加一段
public bool Exist{
get(return this._Exist;}
}

你以前做啥编程的啊,VB还是C啊?_这样的前缀命名规则真别扭啊
ljhcy99 2008-12-15
  • 打赏
  • 举报
回复
加一个属性就可以了

在命名空间BussinessLogicLayer里的User方法代码如下:
using MyChatRoom.DataAccessLayer;
namespace MyChatRoom.BussinessLoginLayer
{

public class User
{
private string _userName;
private string _passWord;
private bool _Exist;
/// <summary>
/// 根据参数userName,获取用户详细信息
/// </summary>
public void LoadData(string userName)
{
Database db = new Database(); //实例化一个Database类
string Sql="select * from [User] where UserName='"+userName+"'";
DataRow dr = db.GetDataRow(Sql); //利用Database类里的GetDataRow方法查询数据库
if (dr != null)
{
this._userName = dr["UserName"].ToString();
this._passWord = dr["PassWord"].ToString();
this._Exist = true;
}
else
this._Exist = false;
}
public bool Exist
{
get{return _Exist;}
set{_Exist= value;}
}

public void Add(string userName, string passWord)
{
Database db = new Database(); //实例化一个Database类
string Sql = "insert [User] values('"+userName+"','"+passWord+"')";
db.ExecuteSQL(Sql); //利用Database类里的ExecuteSQL方法插入数据
}
}
用户界面里Button_onclick的代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
string userName = txtUserName.Text.Trim();
string passWord = txtPassWord.Text.Trim();
MyChatRoom.BussinessLoginLayer.User user = new User();
user.LoadData(userName); //获取用户信息
if (user.Exist)
{
Response.Redirect("Main.aspx");
}
}

游北亮 2008-12-15
  • 打赏
  • 举报
回复
有2种方法:
1、把_Exist设置为属性;
private bool _Exist;
public bool Exist{
get{return _Exist;}
}
这样就可以user.Exist 了

2、在LoadData方法里返回
如:
public bool LoadData(string userName) 
{
Database db = new Database(); //实例化一个Database类
string Sql="select * from [User] where UserName='"+userName+"'";
DataRow dr = db.GetDataRow(Sql); //利用Database类里的GetDataRow方法查询数据库
if (dr != null)
{
this._userName = dr["UserName"].ToString();
this._passWord = dr["PassWord"].ToString();
return true;
}
else
return false;
}

你的代码改成:
if (user.LoadData(userName))   //获取用户信息 
{
Response.Redirect("Main.aspx");
}
wuyq11 2008-12-15
  • 打赏
  • 举报
回复
public bool _Exist;
User user = new User();
gongsun 2008-12-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 gongsun 的回复:]
C# code
if (user.Exist)
{
Response.Redirect("Main.aspx");
}




改为


C# code
if (user._Exist)
{
Response.Redirect("Main.aspx");
}
[/Quote]

改为


if (this._Exist)
{
Response.Redirect("Main.aspx");
}

gongsun 2008-12-15
  • 打赏
  • 举报
回复

if (user.Exist)
{
Response.Redirect("Main.aspx");
}


改为


if (user._Exist)
{
Response.Redirect("Main.aspx");
}

62,269

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧