大家好,以下是我在学习过程中所了解到的一些小知识,希望对大家有所帮助,如果大家还有什么疑问,可以参阅:[url=http://www.cpbdqn.com]网络工程专业[/url] 进行了解。

1、在数据库系统中建立如下数据库表: 
Employee: EMPLID char (5) not null, 
Name  char (10) not null, 
Gender char (1) not null, 
Score   int not null 
此表存储员工信息和考试成绩,为简单起见,这里只包含工号,姓名和性别三项,并且只有一门考试,EMPLID为主键。 

2、建立动态链接库 

启动VB(这里以VB为例,你可以用你喜欢的任何支持ActiveX接口的开发工具开发),新建一工程,工程类型为ActiveX DLL。在工程中新建一个类,取名为Employee。你可以Class Builder可视化的向类中填加属性和方法,也可以直接手工编辑。首先填加EMPLID属性如下: 
Private msEMPLID as string 
Property Let EMPLID(sEMPLID as string) 
msEMPLID=sEMPLID 
End Property 
Property Get EMPLID() as string 
EMPLID=msEMPLID 
End Property 
一般地讲,每一个属性都应该有Property Let和Property Get两个方法,它们分别当向属性赋值和读取属性值时被调用。如果某个属性只被赋值而从不被读取(这种情况多发生在对应数据库表的主键的属性上),则 Property Get方法可以省略。Property Let方法不能省略。你可以仿照上面的程序再建立Name,Gender和Score三个属性。然后创建如下方法: 
Public Sub Create(EMPLID as string) 
dim conn as new Connection 
dim rs as new Recordset 
dim sql as string 
'Suppose that you create a DSN in the control panel, the connectionstring property 
'can also be dsn-less string 
conn.ConnectionString="dsn=dsnname;uid=username;password=pwd" 
conn.open 
sql="select * from Employee where EMPLID='" & EMPLID & "'" 
with rs 
.open sql,conn,1,3 
if .eof and .bof then 
exit sub 
else 
msEMPLID=trim(.Fields("EMPLID")) 
msName=trim(.Fields("Name")) 
msGender=trim(.Fields("Gender")) 
msScore=.Fields("Score") 
end if 
.close 
end with 
set rs=nothing 
conn.close 
set conn=nothing 
End Sub 
这里根据EMPLID创建Employee对象,注意数据库中的值是赋给三个私有变量,而不是直接赋值给属性,如果你单步调试就会发现,给msEMPLID赋值会调用Property Let EMPLID,也就是给属性赋值。