First you need to define variables:
Dim oConn, oRs
the most critical is the 'connection object' (oConn) since that's the point of the whole script, connecting to something.
You also need to define some variables such as your connection string, the path to the database, all the important details.
For learning purposes, you could really do away with the substitution and do it all explicitly...to me the substitution is the tricky part to understand and get right.
So an example of a random connect string WITHOUT all the messy substitution would look like:
oConn.Open("Provider=MSDASQL.1;Password=masterkey;Persist Security Info=True;User ID=sysdba;Data Source=ibdsn1");
But getting back to our variables for a moment.....
Once you have 'filled in the blanks' and populated all the variable values, it's time to pull the trigger:
To do that you need to performing functions associated with that object, such as OPEN, which opens the connection, EXECUTE, which runs something, and CLOSE which closes the database connection.
oConn.Open connectstr
so here you're saying to perform the OPEN function on the oConn object, with the paramters in the variable we called 'connectstr'
Next, we are dumping a SQL database query into the 'qry' variable:
qry = "SELECT * FROM " & tablename
Then pulling the trigger and hoping it works:
Set oRS = oConn.Execute(qry)
the oRS variable holds the 'result' of the query
All the 'if not end' stuff gets a bit tricky, because here is where you need to stuff your database results into your form, or post it on your web page.
If you're building a list on the web page from a database table, you need to grab the records one at a time to post them to the page.
And last but not least, you need to reset your connection and variable, and VERY IMPORANTLY, CLOSE the database connection, or you will slow down the database with too many open connections.
IS there an easier way to do all this?
Heck yes. There is a tool called ASPMAKER which will generate all this code for you. But that would be cheating.