Click here to Skip to main content
13,146,934 members (78,472 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello sir,

I have excel sheet and it contain Name Field and ID field. In my database name as Personal which has Name and ID fields.Now I need to import data from that excel sheet and insert that all data into Personal table in my database.Please tel me how i do this.Data in excel sheet is given below as example
Plz help me.....

Name    ID
a   1
b   2
Posted 2-Oct-12 10:26am
Updated 2-Oct-12 10:31am
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

I have created a Excel AddIn framework that is very easy to customize to any export. You will still have to implement the export move the data from the class which this framework puts the data, and the database. Using Attributes in Excel Add-in Framework for Validating and Exporting Data[^]

Incidently if you are going to vote down, why say why you are voting down. Yes it does not provide a complete solution, but I would like to see you provide the first part of the solution that is better. How you connect to the database has many solutions, and is not dependent on being excel, it can be any database solution, and there are a lot of ways to solve that would apply to any application.
Article? Reference? Otherwise, not helpful. :-)
I think, I found your article. It would probably make a great option, but you better need to reference it.
Clifford Nelson 2-Oct-12 21:25pm
Thanks. Thought I had put it in the solution.
Well, my 5.
I also decided to up-vote your article and advised another member to up-vote.
Clifford Nelson 2-Oct-12 23:34pm
Thanks for the vote of confidence
Achha Insan 3-Oct-12 5:35am
nothing is impossible. you can do it.
It depends: who is that "you" you've mentioned?
Achha Insan 4-Oct-12 7:40am
all the best.
Maciej Los 3-Oct-12 16:34pm
Clifford, please, let me understand...
OP wants to import data from MS Excel into SQL database. You're article is about validating data in MS Excel, using Interop... I'm little confused. How it could be helpful for OP? Am i missed something or am i blind?
BTW, very good articles.
Clifford Nelson 3-Oct-12 17:02pm
The code can be used to help in creating a way to export data from excel. It also provides an easy way move data to an object, providing the user feedback on errors before actually committing to send the data. It still needs the code to actually do the export, but if you have field headers already defined, it can find those headers and read from there. All that needs to be done is to take the C# object and move it into the database.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

You can copy and paste the excel data into a text box and on the "Save" button click, do as follows (remember that data in excel file gets copied as a delimited string, lines separated by "\r\n" or "\n" and columns by "\t"):

//split out the rows first
string[] rows = textBox1.Text.Trim().Split(new char[]{'\r\n', '\n'}, StringSplitOptions.None);
//loop starts from 1 to skip the header row that contains captions i.e. Name, ID etc
for(int i=1;i<rows.length;i++)>
   //for each row we need to split out each individual column
   string[] columns = rows[i].Split(new char[]{'\t'}, StringSplitOptions.None);
   //this bit is pseudocode which you would replace with your SqlCommand etc
   //assign each column value to its corresponding table column
   tablecolumn[0].value = columns[0];
   tablecolumn[1].value = columns[1];
   tablecolumn[2].value = columns[2];
   //finally save this record

This is more or less the way I do my Excel imports, easy, simple and reasonably fast.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Should be enough, a 5.
Maciej Los 3-Oct-12 16:05pm
Thank you Sergey ;)

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170915.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100