The main focus is on the Code. As long as you have done database design, there is basically no problem!
1. VB6-> create a program
Add reference
Project-> reference
Microsoft ActiveX Data Objects 2.8 libray (or another version)
Microsoft ActiveX Data Objects recordset 2.8 libray (or another version)
Create module myconn. bas for database connection)
Call to open a database connection
Call openconn
Close the database connection (RS is used in use, so it is written to the function together with RS)
Call closeconn
The myconn. Bas code is as follows:
1 'define data connection
2 Public conn as new ADODB. Connection
3' define a dataset
4 Public RS as new ADODB. recordset
5' Database Name
6 Public dataname as string
7'database host
8 Public hostip as string
9' User Name
10 public hostuser as string
11' Password
12 public hostpass as string
13 'database connection string
14 public cnstr as string
15
16 'database connection functions
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 use the open method of the connection set to establish a connection with the database
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' disable data
30 public sub closeconn ()
31 Rs. Close
32 set rs = nothing
33 conn. Close
34 set conn = nothing
35 end sub