9.17. Database Example
VBScript does not provide native
database access. As with other functions provided in the WSH
environment, this is implemented using a COM object. ActiveX Data Objects (ADO)
is a COM object that provides database access.The following example uses the
"Northwind" sample database that is
shipped with Microsoft Access. This sample assumes that an ODBC entry
called Northwind exists for the database.
Const adCmdText = 1
Dim objRst, objConn
Set objConn = CreateObject("ADODB.Connection")
objConn.Open "Northwind"
'execute the query against the provider
Set objRst = objConn.Execute("Select * From Customers",, adCmdText)
Do While Not objRst.EOF
Wscript.Echo objRst("CompanyName")
objRst.MoveNext
Loop
objRst.Close
objConn.Close