C# Windows App to upload Excel data to SQL2005  
Author Message
TallMike





PostPosted: Visual C# General, C# Windows App to upload Excel data to SQL2005 Top

Hi,

I took a new job and they want me to write a C# 2005 windows app that allows an end user to browse to an Excel file, select it and then the app uploads a named range into SQL 2005.

I am new to C# and for the past year and a half have been writting stored procedures, before that I had a year of VB6 and lots of VBA (ADO) experience. I have a general understanding of OOP, but no experience except workinh an example from a book last year.

Between learning the new job, SQLServer 2005 and C# I am freaking out cause I only have about three weeks. Has anyone seen any C# code to upload Excel files to get me started.

I would be forever thankful,

Mike



Visual C#12  
 
 
boban.s





PostPosted: Visual C# General, C# Windows App to upload Excel data to SQL2005 Top

There are two aproaches for doing that. One is to do everything in C#, for which you will create new OleDbConnection and will connect to Excel file and read data, and after that or durring reading, you will execute insert commands against SQL server.
Second is to do the task partly in C# and partly in Sql Server. This second way includes to create new Integration Services Project.
You can chose what is easyer for you. Here is one link that i find about how to read Excel data from C#.
http://davidhayden.com/blog/dave/archive/2006/05/26/2973.aspx

 
 
OmegaMan





PostPosted: Visual C# General, C# Windows App to upload Excel data to SQL2005 Top

One could use the Microsoft Office Priamary Interops Assemblies to load up the Excel document, read in the target range from the workbook/sheets and the push it to the database as needed.

If that piques your interest here are two starting points:

How to: Use COM Interop to Create an Excel Spreadsheet (C# Programming Guide)  this will give you a feel for using the interop. This is create, but you will need to load and extract.
Understanding the Excel Object Model from a .NET Developer's Perspective by Ken Getz is leveraged toward VSTO but the example he references has interop calls which you can copy into your application without having VSTO installed.
Office 2003 Update: Redistributable Primary Interop Assemblies