Section 9.17. Database Example

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 



Windows XP in a Nutshell
Windows XP in a Nutshell, Second Edition
ISBN: 0596009003
EAN: 2147483647
Year: 2003
Pages: 266

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net