Database Connection
1. Create ODBC Connection.
Let's say for example, PC2 is where your database is located and PC1 will be the one to establish a connection. From PC1 do the following:
a. Go to control panel + Administrative Tools + Data Sources (ODBC)
b. Click Add button to create a new data source. Select from the list of drivers available.
c. Name your data source and select the database to be used (remember to point this to PC2 database). For the data source name let us use myconnection
VB6 code:
1. Go to Project + References menu, check Microsoft ActiveX Data Objects 2.x (where x is the highest version that you have on your system) and click OK.
2. On form load event let us establish the connection with our database by using the dsn that we've created.
Option Explicit
Dim adoConn as ADODB.Connection
Dim adoRSet as ADODB.Recordset
Dim strSQL as string
'Instantiate
Set adoConn=new ADODB.Connection
'Database Connection string
'DSN is the name of your data source, Uid is the username and Pwd is the password
adoConn.ConnectionString="DSN=myconnection;Uid=admin;Pwd=;"
adoConn.Open
'execute sql select statement
strSQL="select * from table1;"
'instantiate recordset
Set adoRSet=new ADODB.Recordset
adoRSet.Open strSQL,adoConn
'go to 1st record
adoRSet.MoveFirst
do until adoRSet.EOF
'displays the first field of table1
'you can also re write the line below to - adoRSet.Fields("fname").Value
'using the actual field name in table1
Msgbox adoRSet.Fields(0).Value
'move to next record
adoRSet.MoveNext
loop
'close the connection
adoConn.Close
'clean up
Set adoRSet = Nothing
Set adoConn = Nothing