Home

Resources
 
ADO Overview
ADO is a nice way to talk to your AS/400 as it is a very high level object model that is easy to use. ADO abstracts the programmer from the OLE DB interface. You communicate with the AS/400 via an OLE DB provider. This provider can the the Client Access Express OLE DB Provider, the OLE DB Provider from Hit Software or you can use an ODBC provider for the connection via the Microsoft MSDASQL Provider which is an OLE DB provider for ODBC.

You can use ADO from a language like Visual Basic or within Active Server Pages. You can also use ADO in any of the Microsoft scripting languages like JavaScript or VBScript. You can write macros in Word, Excel or PowerPoint to allow these products to interact with data on your AS/400 via ADO.

ADO consists of several high level objects: Connection, Command and Recordset being the most important. A Connection object is used to establish communications with the AS/400. A command object is used to execute stored procedures or prepared SQL statements. A Recordset object is used to iterate through results of SQL statements or stored procedures.

Connecting to the AS/400

The following sample code connects to the AS/400 and retrieves a list of libraries into a recordset. This is VB Code, so it would have to be executed in Word, Excel or the Visual Basic environment in order to function. In addition, Microsoft ActiveX Data Objects would have to be referenced in the VB Project.

Dim Con1 As New ADODB.Connection
Dim Cmd1 As New ADODB.Command
Dim RS As New ADODB.Recordset

Con1.Open "DSN=MY400;UID=HOWARD;PWD=SECRET;"
Cmd1.ActiveConnection = Con1
Cmd1.CommandText = "select distinct system_table_schema from qsys2.systables"
RS.CacheSize = 200
RS.Open Cmd1

In the above example, RS would be instantiated as a recordset object containing the results of the select statement executed against the Cmd1 object.