Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6226403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:01:30+00:00 2026-05-24T09:01:30+00:00

i am preparing myself for importing data from excel sheet to sql server 2005.I

  • 0

i am preparing myself for importing data from excel sheet to sql server 2005.I have few requirements while i import data from excel sheet to database.I have searched a lot but i am unable to find the answer and also i am getting confused,so thought of asking my query over here.The excel sheet format is in this way.

First row contains Heading “Transaction”
Second row contains SubHeading “Date”
From third row the data starts with column names followed by the data in resp.rows.

CustId CustName OUtlet TerminalNum   Date     DateTime               Amount<br/>
   1    Nazima   SS     770012234  1/22/2011   1/22/2011 12:34:45    1500.50<br/>

this is the way the data is in excel sheet.

i have tried to upload the image but it was showing problem while posting the question.so i typed it.

My requirement is that when i import data from excel sheet to database i have to ignore the first two rows and have to import data from third row and i have to import totalamount(62854) and total no.of rows(11) in one table and data in other table.

I am able to import the data using oledbcommand by using this statement:

oledbcommand cmd=new oledbcommand("select * from [sheet1$]",con); and

oledbcomaand cmd=new oledbcommand("select * from [sheet1$A3:H13]",con);

these two statements are working but i dont want it in this way because enduser can enter the data from any cell,so i want to dynamically specify the sheet along with range.In whichever cell the enduser start entering data,the data along with total amount and no.of rows should get imported to reso.tables in database without any problem.

And also i want to know how can i insert a new row in table whenever the end user enters a new row in excel sheet without inserting the previous rows which are already present in table.

Next i want to know which is the best way to import data from excel to database.Is it thru excel interop or thru Oledb.I have tried using import/export wizard,SSIS,they are working but i have to do it programatically.

Give me few guidelines how do i need to carry out these process.

Hope u understood my doubt.

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:01:31+00:00Added an answer on May 24, 2026 at 9:01 am

    Using Interop there will be an easy and better way. However, I never used that and hence don’t know how to use that.

    My requirement is that when i import data from excel sheet to database i have to ignore the first two rows and have to import data from third row and i have to import totalamount(62854) and total no.of rows(11) in one table and data in other table.

    • Load the data to DataSet using OleDbDataAdapter
    • Manipulate on DataSet, i.e do the required operation.
    • Now insert the data from DataSet to your desired Database

    EDIT:

    Sample Code:

        public static void ExcelOperations(string ConnectionString)
        {
            try
            {
                DataTable Sheets = new DataTable();
    
                using (OleDbConnection connection = new OleDbConnection(ConnectionString))
                {
                    connection.Open();
    
                    //Retrieve the Sheets
                    Sheets = connection.GetSchema("Tables");
    
                    //Display the Sheets
                    foreach (DataRow sheet in Sheets.Rows)
                    {
                        Console.WriteLine(sheet["TABLE_NAME"]);
                    }
    
                    //Take the First Sheet
                    string firstSheet = Sheets.Rows[0][2].ToString();
    
                    //Retrieve contents
                    DataSet Contents = new DataSet();
                    using (OleDbDataAdapter adapter = new OleDbDataAdapter("select FirstName,LastName,Email,Mobile from [" + firstSheet + "]", connection))
                    {
                        adapter.Fill(Contents, "MyTable");
                    }
    
                    //Display the contents
                    foreach (DataRow content in Contents.Tables["MyTable"].Rows)
                    {
                        Console.WriteLine(content[0] + " | " + content[1] + " | " + content[2] + " | " + content[3]);
                    }
                    Console.WriteLine();
    
                    //Remove First Row; Note: This is not heading!
                    Contents.Tables["MyTable"].Rows.RemoveAt(0);
    
                    //Since the first row is removed, Second Row becames first row now.
                    //Clearing the LastName of our First Row.
                    Contents.Tables["MyTable"].Rows[0][1] = "";
    
                    //Displaying the Contents
                    foreach (DataRow content in Contents.Tables["MyTable"].Rows)
                    {
                        Console.WriteLine(content[0] + " | " + content[1] + " | " + content[2] + " | " + content[3]);
                    }
                }
    
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been preparing to deliver a presentation on SQL Server Compact Edition 3.5 (SP1
Pros and cons and Usage I have been preparing myself for an interview for
My application is preparing a cover-sheet for submitting documents by fax. I identify the
I'm preparing a class on Visual Basic 2005 targeting Visual Basic 6 programmers migrating
I'm preparing a class on Visual Basic 2005 targeting Visual Basic 6 programmers migrating
Just preparing myself for a task that i feel could be quite troublesome, and
I am preparing myself for a lecture exam on security aspects of software development.
I am preparing myself for programming competitions and i would like to know how
While preparing for the SCJP-6 exam I faced with a difficult issue. I can’t
When preparing a library (let's call it libfoo), I find myself presented with the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.