How can I import an Excel file into SQL Server database?
I am trying to do this:
INSERT INTO temptable SELECT * FROM OPENROWSET( 'Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=\\team4\files\Update_66.xls','SELECT * FROM [Sheet1$]')
I then run into this error:
Cannot create an instance of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)"
Is there a way to do this in powershell perhaps?
Please help me.
After reading Rigerta Demiri's code below, Here is my code:
$dir = "\\server\files\"
$latest = Get-ChildItem -Path $dir | Sort-Object LastWriteTime -Descending | Where-Object {$_.name -like "xyzfile"} | Select-Object -First 1
$SQLServerConnection = "Data Source=rock;Integrated Security=true;Initial Catalog=team;"
$bulkCopy = new-object ("Data.SqlClient.SqlBulkCopy") $SQLServerConnection
$bulkCopy.DestinationTableName = "temptable"
$bulkCopy.WriteToServer($latest)
this code is giving me this error message:
Multiple ambiguous overloads found for "WriteToServer" and the argument count: "1".