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 8370915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:01:45+00:00 2026-06-09T14:01:45+00:00

Am having one excel file with 2 different worksheets as fundmodelrate and project.Now I

  • 0

Am having one excel file with 2 different worksheets as fundmodelrate and project.Now I want to import these 2 different sheet values into 2 different sql tables(k2_fundmodelrate,k2_project).I can able to do import only if am working with 1 sheet and and 1 table,but I want two sheets values to be imported on two tables at the same time on button click event.
My code below:

private String strConnection = "Data Source=kuws4;Initial Catalog=jes;User ID=sa;Password=******";               
        protected void btnSend_Click(object sender, EventArgs e)
        {

            string path = fileuploadExcel.PostedFile.FileName;

            string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\fmr.xls;Extended Properties=Excel 12.0;Persist Security Info=False";

            OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);

            OleDbCommand cmd = new OleDbCommand("Select * from [FundModelRate$]", excelConnection);
            //OleDbCommand cmd1 = new OleDbCommand("Select * from [FundModelRate$],  [Project$]", excelConnection);
            excelConnection.Open();
            OleDbDataReader dReader;
            dReader = cmd.ExecuteReader();
            SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);

            sqlBulk.DestinationTableName = "K2_FundModelRate";
           // sqlBulk.DestinationTableName = "K2_Project";
            sqlBulk.WriteToServer(dReader);
            excelConnection.Close();
        }
  • 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-06-09T14:01:46+00:00Added an answer on June 9, 2026 at 2:01 pm

    I think the only way is to loop through your two sheets.

    Have a look at This post. This will help you get the sheet names.

    When you have the sheet names, you can then just loop through them and then load them into SQL.

    Maybe this can help you:

    OleDbConnection objConn = null;
    System.Data.DataTable dt = null;
    string excelConnection = "";
    
    if(strFile.Trim().EndsWith(".xlsx"))
    {
        excelConnection = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\";", strFile);
    }
    else if(strFile.Trim().EndsWith(".xls")) 
    {
        excelConnection = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\";", strFile);
    }
    
    objConn = new OleDbConnection(excelConnection);
    
    objConn.Open();
    
    dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
    
    String[] excelSheets = new String[dt.Rows.Count];
    int i = 0;
    
    foreach(DataRow row in dt.Rows)
    {
        excelSheets[i] = row["TABLE_NAME"].ToString();
        i++;
    }
    
    for(int j=0; j < excelSheets.Length; j++)
    {
        OleDbCommand cmd = new OleDbCommand("Select * from " + excelSheets[j], excelConnection);
    
        excelConnection.Open();
        OleDbDataReader dReader;
        dReader = cmd.ExecuteReader();
        SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
    
        sqlBulk.DestinationTableName = "YourDestinationTableName";
    
        sqlBulk.WriteToServer(dReader);
        excelConnection.Close();
    }
    

    Note: Not tested

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble with some Excel data validation. On one sheet, I have a
I want to copy an excel file to my database. The problem I'm having
I have data imported from an excel sheet into a table in db. Now
One of my users is having an issue when trying to open an Excel
I am having one Gtk+ and C application in which i want to set
Can any one help me out how can i merge excel files having same
On this project I am working on right now, one of the newest feature
I having problem using CHCSVwriter to export my arrays to CSV or excel file.
I am having trouble writing data to an excel sheet. My other part of
I am trying to import an XLS file into PHP, where I can then

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.