1. Before connecting to the database, you must first select two components, Microsoft ActiveX DataObjects 2.6 library and Microsoft ActiveX DataObjects Recordset 2.6, from the VB menu "Project"-"Reference", which is the necessary work before connecting the data.
2. Next, define the connection object of ADO, as shown below:
Set conn = New ADODB。 relationship
Set rs = New ADODB。 Record set
The first method is the passive database connection method.
conn . ConnectionString = " Driver = { SQL server }; server = jszx 3- 1 1; uid = sapwd =; Database =wzc "
Connection timeout = 30
Control room open
Ruby turns on "Select username and password from login, where username ='"&; Trim (combination 1. Text)& password =' "&; Trim(Text 1。 Text)&",conn, adOpenStatic, adLockReadOnly, adCmdText
If rs. EOF = True and rs. BOF, then
M = MsgBox ("please login again", VB exclamation point)
Text 1。 Text = ""
Text 1。 SetFocus
other
Form 1. hide
If ... it will be over.
rs。 close
This is the second way to connect to the database. This method uses an active method to connect to the database. The code is as follows:
Set conn = New ADODB。 relationship
Set rs = New ADODB。 Record set
conn . ConnectionString = " DSN = log in; uid = sapwd =;"
Connection timeout = 30
Control room open
Ruby opens "Select User Name from Login", conn, adopenstatic, adlockreadonly, adcmdtext.
Mark I as a string
For t = 0 to Val(rs. Record count)-1
I = fine tuning (rs. Field (User Name). Value)
rs。 next step
Combo 1。 AddItem i
Next test
rs。 close