Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

import-csv to Sql

$
0
0

 

 I'm trying to import a file to SQL and I have 2 issues where the string value won't load to my datetime and integer
fields I have defined in SQL. The Effdate and Line seem to be my problem during load. The Effdate could be blank and if not
it's just has Date 1-14-2014 no time in input file. I was always wondering if there is a way to suppress all of the messages(data values) that display on screen for each row in csv.

 Thanks for any help..

foreach ($TableColName in $TableColNames)
        {
           $col_ =  New-Object system.Data.DataColumn $TableColName,([string])
           $Table.Columns.Add($col_)
        }


 Import-Csv -Delimiter '|' -Path $scriptRoot\mfg_plt_ext.txt -header   Itemid,EffDate,Reel,Qty,Line,TranType,OrderNbr,SoldTo,InvoiceNbr,LotSerial,Site,Bol,Pallet,ShipType,MfgPlant|
																								  
      ForEach { 
		               $Row = $Table.NewRow()
		                 $Row.Itemid = $_.Itemid
					     $Row.EffDate = $_.EffDate                                       						 
						 $Row.Reel = $_.Reel
						 $Row.Qty = $_.Qty
						 $Row.line = $_.line
						 $Row.TranType = $_.TranType
						 $Row.OrderNbr = $_.OrderNbr
						 $Row.SoldTo = $_.SoldTo
						 $Row.InvoiceNbr = $_.InvoiceNbr
						 $Row.LotSerial = $_.LotSerial
						 $Row.Site = $_.Site
						 $Row.Bol = $_.Bol
						 $Row.Pallet = $_.Pallet
						 $Row.ShipType = $_.ShipType
						 $Row.MfgPlant = $_.MfgPlant						 								 
					
               $Table.Rows.Add($Row)
             }

$table

#Create SQL Connection 
Write-host "Creating SQL Connection"
$ConnectionString = "Data Source=$sqlsvr;Initial Catalog=$database; Integrated Security=SSPI"
$conn = New-Object System.Data.SqlClient.SqlConnection($ConnectionString)
$conn.Open()


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>