1

i have an excel sheet where i try to upload my excel sheet to sqlserver all having same colum name. now i do not want to add dll files as an web reference in my project. rather place the (dll) in an folder and call them dynamically in .cs side. now i am doing like this

var assembly = Assembly.LoadFrom(@"d:\abc\microsoft.office.interop.excel.dll");

now in my .cs page i need to generate this property or methods of an excel dll which i have loaded dynamically

microsoft.officce.interop.excel.applicationClass excel= null

so that after loading my excel dl dynamically i need to sent values from my excel sheet to sqlserver 2005

is there a way to achive this thank you

Community
  • 1
  • 1
happysmile
  • 7,537
  • 36
  • 105
  • 181
  • Be careful on using the office interop dll. I haven't used it lately much but have been burned with it crashing and consuming large amounts of memory on the web server. – Cody C Feb 19 '10 at 15:49

4 Answers4

0

Can you not use OPENROWSET?
i.e Create a stored procedure that takes the path of the excel file which you want to insert into a given table. Use OPENROWSET function inside it to get a hold of the excel sheet.

shahkalpesh
  • 33,172
  • 3
  • 63
  • 88
0

Aother option is to possibly use SSIS to do this (SQL Server Integration Services). You would have more flexibility and could turn it into a small ETL project.

You could also use Excel code to transmit the data to the database either with a button or a macro. That only works if you can control the Excel file.

Just throwing other options out there.

Cody C
  • 4,757
  • 3
  • 29
  • 36
0

First add a linked server to your Database instance..

Exec sp_dropServer 'myExcel',@droplogins='dropLogins'    
EXEC sp_addlinkedserver 'myExcel',
       'ACE 12.0',
       'Microsoft.ACE.OLEDB.12.0',
       'D:\SAABZX01D\EXCEL_books\ExpressLane\LMI\client carrier conversion.xls',
       NULL,
       'Excel 12.0'
exec sp_linkedServers

Then you insert to myTable in yourDatabase

Insert myTable(cola,colb,colc)
select cola,colb,colc from openQuery(myExcel,'select cola,colb,colc) from sheet1$')
TonyP
  • 5,655
  • 13
  • 60
  • 94
0

You can open an excel file like a database (described here). After this you can load the data into some DataSet (I hope you know how to work with datasets) and upload all to the SqlServer database or to load in some custom structures, update some data if need and insert it into SqlServer database.

Community
  • 1
  • 1
zihotki
  • 5,201
  • 22
  • 26