Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Is there any way to insert records from excel sheet to table in SQL Server
Posted
Comments
_Damian S_ 13-Mar-14 1:49am    
Yes, several. What have you tried?
syna syna 13-Mar-14 1:50am    
can you tell me one which is easy to do
_Damian S_ 13-Mar-14 1:56am    
The easiest is to open SQL Server Management Studio, right click the database you want to import into, click tasks, then import data. It depends whether it's a one off or happening all the time, and whether you have access to the SQL Server or not...

See this Simple way to import data into SQL Server
and There are many other Just Google
 
Share this answer
 
Without Programmatically means, Just use IMPORT data option in sql server or programmatically means


DataSet ds = new DataSet();
String connString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + FilePath + ";Extended Properties=Excel 12.0;";
objConn = new OleDbConnection(connString);
objConn.Open();
dt = objConn.GetOleDbSchemaTable(
OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });

FilePath is uploaded Excel file
 
Share this answer
 
If you want to insert Using T-Sql Code u can use this..
SQL
Exec sp_configure 'show advanced options', 1;
RECONFIGURE;
GO
 
Exec sp_configure 'Ad Hoc Distributed Queries', 1;
RECONFIGURE;
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
-- Using OpenRowSet
SELECT Sno,Data,Row_Number() Over (Order by Sno) as AutoNumber into #XLImport1 
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
				'Excel 12.0 Xml;HDR=YES;Database=C:\test.xlsx','SELECT * FROM [Sheet1$]');

-- Using OpenDataSource
SELECT * INTO #XLImport3 
FROM OPENDATASOURCE('Microsoft.ACE.OLEDB.12.0',
					'Data Source=C:\test.xlsx;Extended Properties=Excel 12.0')...[Sheet1$]

EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0' , N'AllowInProcess' , 0;
GO
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0' , N'DynamicParameters' , 0;
GO
 
Exec sp_configure 'Ad Hoc Distributed Queries', 0;
RECONFIGURE;
GO
 
Exec sp_configure 'show advanced options', 0
RECONFIGURE;
GO
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900