3 回答
TA贡献1744条经验 获得超4个赞
namespace WOODY
{
public class User
{
private int _id;
public int ID
{
get { return _id; }
set { _id = value; }
}
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
}
public interface IUser
{
void Insert(User user);
User GetUser(int id);
}
public class SqlserverUser : IUser
{
public void Insert(User user)
{
HttpContext.Current.Response.Write("在SQL Server中根据ID得到User表增加1条记录");
}
public User GetUser(int id)
{
HttpContext.Current.Response.Write("在SQL Server中根据ID得到User表的1条记录");
return null;
}
}
public class AccessUser : IUser
{
public void Insert(User user)
{
HttpContext.Current.Response.Write("在Access中给User表增加一条记录");
}
public User GetUser(int id)
{
HttpContext.Current.Response.Write("在Access中根据ID得到User表一条记录");
return null;
}
}
public class DataAccess
{
private static readonly string AssemblyName = "WOODY";
private static readonly string db = "Sqlserver";
public IUser CreateUser()
{
string className = AssemblyName + "." + db + "User";
string NAME = this.GetType().Assembly.FullName;
return (IUser)Assembly.Load(this.GetType().Assembly.FullName).CreateInstance(className);
}
}
}
-----
User user = new User();
DataAccess DA = new DataAccess();
IUser iu = DA.CreateUser();
iu.Insert(user);
iu.GetUser(1);
- 3 回答
- 0 关注
- 374 浏览
添加回答
举报