估计你是用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) {} } }
D:\Program Files\Microsoft Visual Studio .NET 2003\Enterprise Samples\Duwamish 7.0 CS 把这个好好看一下
http://community.csdn.net/Expert/topic/4491/4491518.xml?temp=.372616
顺疼摸瓜,浏览浏览吧
其实过程都差不多的,我用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)
{}
}
}
把这个好好看一下
这样实现也可以不过也可以建立设备类后,手动通过查询DB 加载相应设备
编写一个Helper类,来实现相应功能~