You can use the ADODB object and the Recordset object to run database queries and retrieve data. The steps are pretty much the same for each database. The connection string is sometimes the tricky part and depends on the database you want to work with. The best place to find examples of database connection strings is www.connectionstrings.com
Here are a few examples:
'Exporting some data from a SQL Server db to a text file
Set objCon=createobject(''Adodb.connection'')
Set objRs=createobject(''Adodb.Recordset'')
set objFso=createobject(''Scripting.Filesystemobject'')
Set myFile=objFso.OpenTextFile(''C:database.txt'',8)
connstring = ''Server=myServerAddress;Database=myDataBase;User Id=myUsername;
Password=myPassword;'' 'just a dummy string
objcon.open connstring
objrs.open ''select * from users'',objCon
r=1
Do until objRs.EOF
f=objRs.Fields (''First'')
l=objRs.Fields (''Last'')
myFile.Writeline f &'',''& l
r=r+1
objRs.MoveNext
Loop
myFile.Close
objCon.Close
'Display the results of a database query against SQL Server Express edition
'Create the database connection object
Set objConnection = CreateObject(''ADODB.Connection'')
'Create RecordSet Object
Set objRecordSet = CreateObject(''ADODB.Recordset'')
'Query to be Executed
DBQuery = ''Select NAME from dbo.USERS where ID = 199''
'Connect using SQL OLEDB connection string
objConnection.Open ''Provider=sqloledb.1;Server=.SQLEXPRESS;User Id=sa;Password=PasswordXYZ;Database=Samples''
'Execute the query
objRecordSet.Open DBQuery,objConnection
'Retrieve the result set
Value = objRecordSet.fields.item(0)
msgbox Value
'Release the objects from memory
objRecordSet.Close
objConnection.Close
Set objConnection = Nothing
Set objRecordSet = Nothing