主要侧重与代码方面,关于数据库设计,只要你做过,基本没有什么问题!
1.VB6->新建程序
添加引用
工程—>引用
Microsoft ActiveX Data Objects 2.8 Libray (或其它版本)
Microsoft ActiveX Data Objects Recordset 2.8 Libray (或其它版本)
新建模块MyConn.bas(用于数据库连接)
调用打开数据库连接
Call OpenConn
关闭数据库连接(用的时候用到rs,所以连同rs写到函数里了)
Call CloseConn
MyConn.bas代码如下:
1 '定义数据连接
2 Public conn As New ADODB.Connection
3 '定义数据集
4 Public rs As New ADODB.Recordset
5 '数据库名称
6 Public Dataname As String
7 '数据库主机
8 Public hostip As String
9 '用户名
10 Public hostuser As String
11 '密码
12 Public hostpass As String
13 '数据库连接字符串
14 Public Cnstr As String
15
16 '连接数据库函数
17 '-------------------------------------------------
18 Public Sub OpenConn()
19 'Cnstr = "PROVIDER=MSDataShape;Data PROVIDER=MSDASQL;uid=" & DbUser & ";pwd=" & DbPw & ";DRIVER=SQL Server;DATABASE=" & DbName & ";WSID=GQSOFT;SERVER=" & DbIP
20 'conn.Open Cnstr 使用 Connection 集合的 Open 方法 与数据库建立连接
21
22 hostip = "192.168.9.71"
23 hostuser = "sa"
24 hostpass = "bmschool"
25 Dataname = "Vehicle"
26 conn.ConnectionString = "Driver={SQL Server};server=" & hostip & ";uid=" & hostuser & ";pwd=" & hostpass & ";database=" & Dataname & ""
27 conn.Open
28 End Sub
29 '关闭数据
30 Public Sub CloseConn()
31 rs.Close
32 Set rs = Nothing
33 conn.Close
34 Set conn = Nothing
35 End Sub
2 Public conn As New ADODB.Connection
3 '定义数据集
4 Public rs As New ADODB.Recordset
5 '数据库名称
6 Public Dataname As String
7 '数据库主机
8 Public hostip As String
9 '用户名
10 Public hostuser As String
11 '密码
12 Public hostpass As String
13 '数据库连接字符串
14 Public Cnstr As String
15
16 '连接数据库函数
17 '-------------------------------------------------
18 Public Sub OpenConn()
19 'Cnstr = "PROVIDER=MSDataShape;Data PROVIDER=MSDASQL;uid=" & DbUser & ";pwd=" & DbPw & ";DRIVER=SQL Server;DATABASE=" & DbName & ";WSID=GQSOFT;SERVER=" & DbIP
20 'conn.Open Cnstr 使用 Connection 集合的 Open 方法 与数据库建立连接
21
22 hostip = "192.168.9.71"
23 hostuser = "sa"
24 hostpass = "bmschool"
25 Dataname = "Vehicle"
26 conn.ConnectionString = "Driver={SQL Server};server=" & hostip & ";uid=" & hostuser & ";pwd=" & hostpass & ";database=" & Dataname & ""
27 conn.Open
28 End Sub
29 '关闭数据
30 Public Sub CloseConn()
31 rs.Close
32 Set rs = Nothing
33 conn.Close
34 Set conn = Nothing
35 End Sub