sql - BULK INSERT a xlsx file -
i have been struggling import .xlsx
file while , cant seem figure out happening. follow steps find in other posts, , other tutorials.
i have simple .xlsx
file now:
this the code run grab file , put temp table now:
if object_id('tempdb..#compare') not null drop table #compare; create table #compare ( name varchar(max) ,lastname varchar(max) ); bulk insert #compare 'c:\users\michael\documents\taquanta\taqkanban - 44 - 3pm compare\compare.xlsx' ( fieldterminator = '\t', rowterminator = '\n' ) go select * #compare c
and results returned not expected :(
the results:
please let me know going wrong?
i've done powershell several times. adapt following.
$filename = "c:\users\michael\documents\taquanta\taqkanban - 44 - 3pm compare\compare.xlsx"; $excelconnstr = "provider=microsoft.ace.oledb.12.0;data source='$filename';extended properties='excel 12.0 xml;hdr=yes';" $excelconn = new-object system.data.oledb.oledbconnection($excelconnstr); $excelconn.open(); $excelcommand = new-object system.data.oledb.oledbcommand("select * [sheet1`$a5:ae]" ,$excelconn); $adpt = new-object system.data.oledb.oledbdataadapter; $adpt.selectcommand = $excelcommand; $dt = new-object system.data.datatable; [void]$adpt.fill($dt); $sqlconnstr = "server=xxxxx;database=xxxxx;trusted_connection=true;"; $sqlbulkcopy = new-object system.data.sqlclient.sqlbulkcopy($sqlconnstr); $sqlbulkcopy.destinationtablename = "dbo.tablename" $sqlbulkcopy.writetoserver($dt); $sqlbulkcopy.close();
Comments
Post a Comment