Insert Excel data to Sql and Sql table data to Excel file
Posted by Sujit Kumar on August 23, 2008
First execute this procedure
EXEC sp_configure ’show advanced options’, 1;
GO
RECONFIGURE;
GO
EXEC sp_configure ‘Ad Hoc Distributed Queries’, 1;
GO
RECONFIGURE;
GO
After executing procedure then write the query
to insert sql table data to excel file.
INSERT INTO OPENROWSET (‘Microsoft.Jet.OLEDB.4.0′, ‘Excel 8.0;Database=c:\contact.xls;HDR=YES;’,
‘SELECT * FROM [SheetText1$]‘)
SELECT * from TableName
_____________________________________________________________________________________
to insert excel data to sql table
Insert into dbo.tableName
select * from openrowset(‘Microsoft.Jet.OLEDB.4.0′,’Excel 8.0;database=C:\contact.xls’,
’select * from [Sheet1$]‘)
NOTE:
Excel columns and Table Columns should be same.
Sandeep said
Thanks For Ur Code i Have Execute it
Deepak kataria said
Hi Sujit,
I am using Visual Studio 2005,Sql server 2005, and office 2007
I got below error.
Cannot get the column information from OLE DB provider “Microsoft.Jet.OLEDB.4.0″ for linked server “(null)”.
Sujit Kumar said
have you executed these line ??
To Enable Ad Hoc Distributed Queries. Run following code in SQL Server Management Studio – Query Editor.
EXEC sp_configure ’show advanced options’, 1;
GO
RECONFIGURE;
GO
EXEC sp_configure ‘Ad Hoc Distributed Queries’, 1;
GO
RECONFIGURE;
GO
———
after executed the above lines, still you get the error then copy your excel file in root directory (c:) then try to execute.
Swapnil said
Good article lots of help me!!!!!
Thanks!!!!!!