Last active
December 13, 2015 17:49
-
-
Save krote/4950864 to your computer and use it in GitHub Desktop.
PowerShell Oracle Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[void][reflection.assembly]::LoadWithPartialName("System.Data.OracleClient") | |
$ConnectionString = "Data Source=/******/;User ID=/*****/;Password=/*****/;Integrated Security=false;" | |
$OraConn = New-Object System.Data.OracleClient.OracleConnection($ConnectionString) | |
$dtSet = New-Object System.Data.DataSet | |
$strSQL = "SELECT * FROM EMP" | |
#Make Data Adapter | |
$oraDA = New-Object System.Data.OracleClient.OracleDataAdapter($strSQL, $OraConn) | |
########################## | |
#Data Get | |
[void]$oraDA.Fill($dtSet) | |
$dtSet.Tables[0] | Format-Table | |
#Make Command Builder | |
$OraCB = New-Object System.Data.OracleClient.OracleCommandBuilder($oraDA) | |
########################### | |
#Make New Record | |
$dtRow = $dtSet.Tables[0].NewRow() | |
$dtRow["ID"] = "001" | |
$dtRow["NAME"] = "krote" | |
$dtSet.Tables[0].Rows.Add($dtRow) | |
[void]$oraDA.Update($dtSet) | |
######################## | |
#Delete Data | |
$dtRows= $dtSet.Tables[0].Select("ID=001") | |
foreach($dtRow in $dtRows) | |
{ | |
$dtRow.Delete() | |
} | |
$dtSet.Update($dtSet) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment