Part 3 of 3
Now, in this sample we are going to executre an i5 command to clear a table. This is the Clear Physical Member command "
CLRPFM". In ADO.NET, we are going to use the OLEDbCommand() to hold the command to be executed.
You have to make sure to use the open/closing double brackets "{{ }}" or it will not work. Then, using the ".
ExecuteNonQuery()" to execute the command.
Again, make sure your i5 Security Officer give you the permission required to execute this command.
Executing an i5 command
|
## Load GAC
[System.Reflection.Assembly]::LoadWithPartialName("System.Data")
[System.Reflection.Assembly]::LoadWithPartialName("IBM.Data.DB2.iSeries")
## Setup you userID and Password
[string] $i5UID = 'YourName_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();
## Perform a i5 command to clear physical file member
$cmd = New-Object System.Data.OleDb.OleDbCommand("{{CLRPFM SALES/EURSTRMST}}",$I5Conn);
$cmd.ExecuteNonQuery() | Out-Null;
$i5Conn.Close();
|
I you have notice, I'm piping the '$cmd.ExecuteNonQuery()' to a 'Out-Null' cmdlet becuase I don't want the result to returned to the consoie. Now, during debuggin ypou may want to avoid using this so you can see the numbers of record been affected or a returned value (0 or 1).
As you can see with these three blog entries you can connect, query, and run a command on your i5 System.