访问类库里边的类时,只能访问到属性,不能访问到方法,在线等!

ljb1981216 2004-06-10 09:24:41
我写的一个class Base :
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Security.Cryptography;
using System.Text;
using Mis.DbBase;

namespace Mis.DbBase
{
public class User:Mis.DbBase.Base
{
private string m_Password;
private string emp_id;

public string Password
{
get{return m_Password;}
set{m_Password=value;}
}
public string Emp_Id
{
get{return emp_id;}
set{emp_id=value;}
}
public static void Add(string name,string password,string Emp_Id)
{
if(IsExist(Emp_Id))
{throw new Exception("This Name was registered");}
else
{
strSQL ="Insert into t_emp_info(emp_name,Password,emp_id) values("
+""+name+","
+""+password+","
+""+Emp_Id+")";
try
{ExecuteSql(strSQL);}
catch
{ throw new Exception("register failed");}

}
}
public static void Delete(int id)
{
strSQL="update t_emp_info set flag='0'where emp_id ="+id;
try
{ExecuteSql(strSQL);}
catch
{ throw new Exception("Register Failed");}
}

public static bool IsExist(string Emp_Id)
{
strSQL="select emp_id from t_emp_info where flag=1 and emp_id ='+id'";
try
{
ExecuteSql4Value(strSQL);
return true;}
catch
{
return false;
}
}

}

}


在引用这个类库时:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using Mis.DbBase;
using DbBase;

namespace TheRest
{
/// <summary>
/// empFrm 的摘要说明。
/// </summary>
public class empFrm : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button1;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
Mis.DbBase.User user=new Mis.DbBase.User();

user.ID=TextBox1.Text;
user.Name=TextBox2.Text;


}
}
}

当我试图访问user对象时,只能访问到user下边的属性ID和Name,却不能访问user的方法Add(string name,string password,string Emp_Id);也就是当我输入user.的时候,后边只提示我的属性ID和Name,却没有方法Add(string name,string password,string Emp_Id)的提示;
请问高手,我怎么解决这样的问题?
...全文
84 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
活力华华哥 2004-06-10
  • 打赏
  • 举报
回复
你不用静态方法就行了,把static 去掉
ljb1981216 2004-06-10
  • 打赏
  • 举报
回复
lcy00(lcy),我已经揭贴了,谢谢你
能留你的hotmail或qq吗?
ljb1981216 2004-06-10
  • 打赏
  • 举报
回复
lcy00(lcy),我已经揭贴了,谢谢你
能留你的hotmail或qq吗?
lcy00 2004-06-10
  • 打赏
  • 举报
回复
静态的是不需要实例化就可以使用的
ljb1981216 2004-06-10
  • 打赏
  • 举报
回复
静态和动态方法的区别是什么?使用起来有什么差别吗?
lcy00 2004-06-10
  • 打赏
  • 举报
回复
Mis.DbBase.User user=new Mis.DbBase.User();

user.ID=TextBox1.Text;
user.Name=TextBox2.Text;

Mis.DbBase.User.Add(user.Name,'',user.ID);
Add方法是静态方法
ljb1981216 2004-06-10
  • 打赏
  • 举报
回复
还有为什么利用这个类Mis.DbBase.User.Add()有这个方法,我利用类生成的对象就没有这个方法了?希望大家说详细点,我想利用Mis.DbBase.User user=new Mis.DbBase.User()这个user对象,然后还要使用Add(string name,string password,string Emp_Id)这个方法,谢谢贴出源码的实现。
ljb1981216 2004-06-10
  • 打赏
  • 举报
回复
Mis.DbBase.User.Add(),是有这个方法,
但是我要利用user对象呀,要不我怎么使用这个方法呀?请说详细点。
hfwang009 2004-06-10
  • 打赏
  • 举报
回复
Mis.DbBase.Add(...)

110,556

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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