Part 2 of 3
Using the provider IBM ADO.NET provider, in this sample will query a table in our i5 System. Now, in this sample code it will access the table and display onky the first 10 records.
DB2 Query using IBM ADO.NET
|
## Load GAC
[System.Reflection.Assembly]::LoadWithPartialName("System.Data")
[System.Reflection.Assembly]::LoadWithPartialName("IBM.Data.DB2.iSeries")
## Setup User
[string] $i5UID = 'YouUserID_here';
[string] $i5PWD = 'YourPassword_here';
## Create connection to i5Serie
$i5Conn = New-Object System.Data.OleDb.OleDbConnection("Provider=IBMDA400;Data Source=IBMeServer;User ID=$i5UID;Password=$i5PWD;Initial Catalog=S1042B3A");
$i5Conn.Open();
## Select records to build a dataset collection
$ds = new-object "System.Data.DataSet"
$q = "SELECT EUSTRN,EUODAT,EUCDAT FROM Sales.EURSTRMST"
$da = new-object "System.Data.OleDb.OleDbDataAdapter" ($q, $i5Conn)
$da.Fill($ds)
## Loading records into the object
$c = $ds.tables | Select rows
## Display the first 10 records
$c.rows | Select -First 10
|
As you might notice, how do I get the properties ".tables" and/or ".rows". You can find these properties by using the "get-member" or the alias "gm" everytime you create a variable.
Next, will use PowerShell to execute an i5 command.