[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

import data from CSV file into the sql server database

Posted on 2008-10-09
3
Medium Priority
?
1,111 Views
Last Modified: 2012-05-05
Hello Experts,
 I have a CSV file which holds questions and multiple choice information in the CSV file. I am trying to
create a page where I can read the data from this file and insert all the questions into the QUESTIONS table and 4 multiple choice options into the OPTIONS table.
 Please can someone help me in this.
 Your help is much appreciated.
 Regards
 Kay
Test1.xls
0
Comment
Question by:learningnet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Expert Comment

by:Sander Stad
ID: 22677947
There is standard functionality in SQL Server 2005 that lets you do this. it is called SSIS (SQL Server Integrated Services).
Look at this article from www.basejournal.nl to see how you can import data from your XLS or CVS file. Remember that you'd probably have to import the data for every table. So in your case you'd have to do this oncehe QUESTIONS and once for the OPTIONS table.
URL: http://www.databasejournal.com/features/mssql/article.php/3580216 
0
 

Author Comment

by:learningnet
ID: 22678064
thanks sstad for the links

apparently i cannot use that way because this has to go in the admin section of the were a user can upload the questions into the DB

please see the tables format attached

thanks
Questions
---------
QuestionID	TestID	QuestionContent					QuestionNumber	
1		1	A passive background to a story provides	1
2		1	Which one of the following a location		2
 
Options
--------
OptionId	Option							OptionNumber	Correct QuestionId 
1		An incidental background and setting for the story	0	1	1	1
2		A background to the story that has significant		1	0	1	1
3		A small location set in a rural community 		2	0	1	1
4		A big location that impacts the story			3	0	1	1
5		The cell was a tiny room. It just containednd basin. 	0	0	2	1
6		Tom travelled his entire world in ten steps 		1	1	2	1
7		The cell was ten foot. Tom had been in prison for 	2	0	2	1
8		Tom had been in prison for two years			3	0	2	1

Open in new window

0
 
LVL 9

Accepted Solution

by:
Sander Stad earned 2000 total points
ID: 22678206
I probably found something you can use. What you have to do is create an upload tool for your webpage. So if someone uploads the file(s) they are placed in a temp dir on your webserver.
You'd have to create a BULK INSERT to do this in SQL Server that will take care of the inserts into the tables.
Look at this article: http://blog.sqlauthority.com/2008/02/06/sql-server-import-csv-file-into-sql-server-using-bulk-insert-load-comma-delimited-file-into-sql-server/
So to be clear this is what you have to do:
  1. Create an upload tool in your webpage that uploads the csv file
  2. Create a stored procedure that has a parameter with the just uploaded file. In an server-side language you can return the value of the just submitted csv file back to you so you can give it to the stored procedure.
  3. Do this seperately for every table, so twice in your example. One for your questions table and one for your options table.

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

656 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