我设计了一个仓库类,里面有一个设备属性,是vector类型的,我有一张叫设备的表,里面记录了仓库里所有设备的种类(每条记录一种设备),那该用什么方法,把表的内容的记录一一对应成vector的记录呢?有没有教怎么样把面向对象编程与关系数据库结合的的书呀?谢谢

解决方案 »

  1.   

    给你一个研究这方面的帖子的连接:
    http://community.csdn.net/Expert/topic/4491/4491518.xml?temp=.372616
    顺疼摸瓜,浏览浏览吧
      

  2.   

    估计你是用VC的吧.
    其实过程都差不多的,我用C#做个简单例子给你看看.
    设备表结构:
    ID
    设备名
    说明
    那么我们可以设计一个类来装载它
    public class 设备
        {
            public int _id;
            public string _设备名;
            public string _说明;        public int ID
            {
                get { return this._id; }
                set { this._id = value; }
            }
            public int 设备名
            {
                get { return this._设备名; }
                set { this._设备名 = value; }
            }
            public int 说明
            {
                get { return this._说明; }
                set { this._说明 = value; }
            }        public 设备(int __id, string __设备名,__说明)
            {
                this.ID=__id;
                this.设备名=__设备名;
                this.说明=_说明;
            }
        }    public class 使用
        {
            public string constr="..........";
            public List<设备> 全部设备=new List<设备>();        public 使用()
            {}        public void 获取全部设备()
            {
                this.全部设备.Clear();
                SqlConnection con=new SqlConnection(this.constr);
                SqlCommand com=new SqlCommand("select * from 设备表",con);
                try
                {
                    con.Open();
                    SqlDataReader read= com.ExecuteReader();
                    while(read.Read())
                    {
                        this.全部设备.Add(new 设备(((int)read["ID"]),read["设备名"].ToString(),read["说明"].ToString()));
                    }
                }
                catch(Exception ex)
                {}
            }
        }
      

  3.   

    D:\Program Files\Microsoft Visual Studio .NET 2003\Enterprise Samples\Duwamish 7.0 CS
    把这个好好看一下
      

  4.   

    ajqc(失眠无神闷坐中) 的那段代码是用到C# 2.0中的泛型吧
    这样实现也可以不过也可以建立设备类后,手动通过查询DB 加载相应设备
    编写一个Helper类,来实现相应功能~
      

  5.   

    看看ORM吧,.net下的工具好像是叫NHibernate。