Solved

Importing data from Excel in Database SQL2005

Posted on 2006-11-27
10
206 Views
Last Modified: 2010-04-16
Hi,

I am working in C# and making Windows Application.

I have an excel file to which I want to import in the database SQL 2005

How can i do this, also I do not want to make dsn, but i can make file DSN

Can anyone help me in this regard

Thanks in Advance
0
Comment
Question by:dinesh_bali
  • 3
  • 2
  • 2
10 Comments
 
LVL 12

Expert Comment

by:AGBrown
ID: 18020919
Would it be possible to use Integration Services to do this in your situation? It won't be as easy to do it on-demand, but you could schedule the SQl agent to run the SSIS job every minute, and get that job to pick up any spreadsheets sitting in a certain directory? It really depends on whether this is a local application, or a web application, and how SQL server is setup (and which version you are running).

A.
0
 

Author Comment

by:dinesh_bali
ID: 18024023
Ok, If you have the solution with DSN or some other,

that if user click on the button then the filtered data goes into sql 2005

Thanks in Advance
0
 
LVL 12

Expert Comment

by:AGBrown
ID: 18024031
Is this a web application, or a windows application?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 18025478
You can import excel file into SqlServer using SqlServer Enterprize Manager try following:

Select Tools tab.
In that select Data Transformation Services.
In that select import Data
Then you follow the wizard.

Hope this helps.

Another approach I used some time ago : I read data from Excel to DataSet, just need appropriate connection string
Then changed connection and saved into database. Can't remember details exactly but it worked well and was quite easy.
0
 

Author Comment

by:dinesh_bali
ID: 18032439
I want to do using C# code.

My excel format and database format is not same.

So I need to filter the data from C# SQL Query and then insert the data in the database.

Can you please help me in this context
0
 
LVL 29

Accepted Solution

by:
anarki_jimbel earned 500 total points
ID: 18033285
I believe it's not so hard.

See the link how to read data from Excel. Very simple and easy to follow.
You may also filter the data at this stage using SQL:

http://zamov.online.fr/EXHTML/CSharp/CSharp4.html

Once you have your data in the DataSet I believe it's pretty easy to write the data to database.
You may also want to create another DataSet and copy necessary data from the first one to the second one, etc.
Or e.g. create new tables in the second dataset and fill them with data from the first dataset, and save second dataset into database.
0
 
LVL 12

Expert Comment

by:AGBrown
ID: 18033657
It is certainly possible, but there's all sorts of inherent problems with this. For one, Excel is a user application, so it might flash up "dialog boxes" in the "user space" of the account running your code. If your code is a web application, this can freeze your web application. Secondly, Jet is pretty bad at recognising data types. If the first 5 rows of data in one column look like numbers, but there is a text string somewhere in that column, it will cause errors.

So it really comes back to what the end-use of this is; server (web or other) application, or a user application? Is the SQL server a local install, or a centrally managed server?

A
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now