This web site uses Kentico CMS, the content management system for ASP.NET developers.
Community > Blogs > Max-PIT> IBM i5Series and PowerShell > December 2008 > PowerShell DB2 Query to an i5 Table
 

PowerShell DB2 Query to an i5 Table

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.
Posted: 12/6/2008 4:36:26 PM by Global Administrator | with 1 comments


Comments
oqhiulzl
pWhj3F pudqdbedqksf, [url=http://surkfgbgtxtc.com/]surkfgbgtxtc[/url], [link=http://gpjppdzwsecb.com/]gpjppdzwsecb[/link], http://wqbdznrrpsym.com/
4/5/2009 6:39:43 PM

Title

Due to the fact that I have to also work with our IBM i5Series (aka AS/400), I needed to build a solution push data into the system.  So, using the "IBM iSeries Access for Windows" .NET provider, I was able to connect and use our DB2 databses in our i5 system.

It was hard for me to find information on How-to use the 'IBM iSeries Access to Windows" .NET provider to get my PowerShell script to work. I found one link (that I lost again) and a iSeries .NET presentation (C# code), help me complete these samples.

This blog section will provider with the necessary samples to:
1. Get connected to the i5 System
2. Do a SQL Query to a DB2 table
3. Executing a i5 Command

Please, make sure the your "security Office" provide you with the properly configured user ID and Password.


My favourite websites

Syndication

RSS

Post archive

This web site uses Kentico CMS, the content management system for ASP.NET developers.