OK, there are a number of different methods, but the most used one is via ODBC.
Here is some sample code from a program I use to connect to a database - you will need to reference the Microsoft AcitveX Data Objects Library (I'm using version 2.7) to provide access to the appropriate classes though:
Code:
Set myConnection = CreateObject("ADODB.Connection")
If DSN <> "" Then DSNbit = "Data Source=" & DSN
If DB <> "" Then DBbit = "database=" & DB
If user <> "" Then USERbit = "User ID=" & user
If pwd <> "" Then PWDbit = "Password=" & pwd
myConnection.ConnectionString = DSNbit & ";" & USERbit & ";" & PWDbit & ";" & DBbit & ";"
myConnection.Open
'Now the connection has been established, you can execute SQL commands using the following syntax.
sqlstring = "insert into mytable (name, number) values ('Chris', 4)"
myConnection.Execute sqlString
'To pull data from the database, use a recordset object
sqlString = "Select foo, bar from mytable"
set rs = new RecordSet
rs.open sqlString, myConnection
That's the code stuff, the actuall connection is made by setting up an ODBC driver (sometimes known as a DSN) on your client machine that points to the appropriate SQL Server. Setting up the connection is done via the Start...Settings...Control Panel...Administrative Tools...Data Sources (ODBC) - then decide whether you want a User DSN or a System One and carry on from there.
Once that's setup - your code should be pretty straight-forward.