Database Reference
In-Depth Information
to the following COUNTRIES table:
Getting ready
See previous recipes for the Add-Oracle , Get-ScriptDirectory , and connection
functions used in this recipe.
How to do it...
1.
Load the countries XML ile into a DataTable and add a REGION_ID column:
$regionId = 5
$ds = New-Object System.Data.DataSet
$srcFilename = (join-path (Get-ScriptDirectory) countries.xml)
[void]$ds.ReadXml($srcFilename)
$regionCol = New-Object System.Data.DataColumn("REGION_ID", [int])
$regionCol.DefaultValue = $regionId
$regionCol.ColumnMapping = [System.Data.MappingType]::Attribute
$countryDT = $ds.Tables["country"]
$countryDT.Columns.Add($regionCol)
2.
Connect and insert a region record for the countries to be imported:
$conn = Connect-Oracle (Get-ConnectionString)
Add-Oracle $conn "INSERT INTO REGIONS (REGION_ID, REGION_NAME)
VALUES ($regionId, 'Test Region')"
3.
Set up an OracleBulkCopy object:
$bulkCopy = New-Object Oracle.DataAccess.Client.
OracleBulkCopy($conn) `
-property @{DestinationTableName = "COUNTRIES";
BulkCopyTimeout = 300; NotifyAfter = 50}
[void]$bulkCopy.ColumnMappings.Add("code", "country_id")
[void]$bulkCopy.ColumnMappings.Add("country_Text", "country_name")
[void]$bulkCopy.ColumnMappings.Add("region_id", "region_id")
 
Search WWH ::




Custom Search