Aakash Shah
Aakash Shah

Reputation: 11

Import Excel data to SQL Server

I want to insert the data from excel file into the SQL Server.. I used the following SQL Statement:

SELECT * 
  FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
                  'Excel 8.0;Database=Y:\Path.xls',
                  'SELECT * FROM [Sheet$]')

But i am getting the following error -

Msg 7403, Level 16, State 1, Line 1
The OLE DB provider "Microsoft.Jet.OLEDB.4.0" has not been registered.

Upvotes: 0

Views: 1446

Answers (4)

Parul
Parul

Reputation: 1

You can use below code to import the data in SQL from Excel. Just you need to understand that you have to add a library in VBA and only then you will use below code. Go in VBA and then add reference – Microsoft ActiveX Data objects 2.8 Library.

Sub sbADOExample()
Dim sSQLQry As String
Dim ReturnArray
Dim Conn As New ADODB.Connection
Dim mrs As New ADODB.Recordset
Dim DBPath As String, sconnect As String
DBPath = ThisWorkbook.FullName
'You can provide the full path of your external file as shown below
'DBPath ="C:\InputData.xlsx"
sconnect = "Provider=MSDASQL.1;DSN=Excel Files;DBQ=" & DBPath & ";HDR=Yes';"
Conn.Open sconnect
sSQLSting = "SELECT * From [Sheet1$]" ' Your SQL Statement (Table Name= Sheet Name=[Sheet1$])
mrs.Open sSQLSting, Conn
'=>Load the Data into an array
'ReturnArray = mrs.GetRows
''OR''
'=>Paste the data into a sheet
Sheet2.Range("A2").CopyFromRecordset mrs
'Close Recordset
mrs.Close
'Close Connection
Conn.Close
End Sub

Upvotes: 0

Zame
Zame

Reputation: 320

Try running this:

USE [tableName]
GO

EXEC master . dbo. sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0' , N'AllowInProcess' , 1
GO

EXEC master . dbo. sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0' , N'DynamicParameters' , 1
GO

in your query

and use Microsoft.ACE.OLEDB.12.0 instead of "Microsoft.Jet.OLEDB.4.0" , works for me

Upvotes: 0

niktrs
niktrs

Reputation: 10066

If you are using SQL Server version>=2005 you can use management studio or SSIS.

check the link http://msdn.microsoft.com/en-us/library/ms140052(v=SQL.90).aspx

Upvotes: 0

Nitesh
Nitesh

Reputation: 2337

You can use Import data wizard of SQL Server instead.

Upvotes: 2

Related Questions