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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:13:44+00:00 2026-06-17T13:13:44+00:00

I am new to c# and i have a simple project on c# in

  • 0

I am new to c# and i have a simple project on c# in which i want to get some data from excel in c# and i want to save it in database, i have no idea about it, i found the following code and its working well but not giving me the data, here is code:

 var fileName = @"C:\Users\AhsanWindows8\Desktop\Book1.xlsx";
        var connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties=\"Excel 12.0;IMEX=1;HDR=NO;TypeGuessRows=0;ImportMixedTypes=Text\""; ;
        using (var conn = new OleDbConnection(connectionString))
        {
            conn.Open();

            var sheets = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
            using (var cmd = conn.CreateCommand())
            {
                cmd.CommandText = "SELECT * FROM [" + sheets.Rows[0]["TABLE_NAME"].ToString() + "] ";

                var adapter = new OleDbDataAdapter(cmd);
                var ds = new DataSet();
                adapter.Fill(ds);
            }
        }

now this is how my excel file looks like

enter image description here

Can I get this data in a dictionary like key value pair, suppose English word on left side will be key and text on right side will be value.

  • 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-17T13:13:45+00:00Added an answer on June 17, 2026 at 1:13 pm

    Try this:

    cmd.CommandText =
            "SELECT * FROM [" + sheets.Rows[0]["TABLE_NAME"].ToString() + "$] ";
    

    When dataset will be filled you can use this code to construct dictionary.

    var dict = new Dictionary<string, string>();
    foreach(DataRow row in ds.Tables[0].Rows)
    {
      dict.Add(row[0].ToString(), row[1].ToString());
    }
    

    If you are familiar with LINQ, you can try use this:

    ds.Tables[0].Rows.ToDictionary(r => r[0].Tostring(), r => r[1].Tostring());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have avery simple program which uses MediaPLayer. I am new to java and
I'm new to SQL. I have a simple problem with getting the results from
I have a view based iPhone project which performs some animations & suchlike, Seperately
I have a large-ish web project which is migrating from classic ASP to ASP.NET
All, I have a VB6 project with about 100 custom collection classes which I
I have a simple query: $query = new WP_Query('showposts=5'); that will obviously display 5
I have this simple piece of code: MyObjectContext db = new MyObjectContext(); Person new_person
I have a simple has_one/belongs_to relationship between two models. This is a new association
I have a simple code byte[] buffer = Encoding.UTF8.GetBytes(abracadabra); MemoryStream ms = new MemoryStream();
i have a simple if condition as follows... $site = new-object Microsoft.SharePoint.SPSite($url) $sitelists =

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.