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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:19:08+00:00 2026-05-15T01:19:08+00:00

I’ve a requirement that I need to read an excel sheet programmatically using asp.net/C#

  • 0

I’ve a requirement that I need to read an excel sheet programmatically using asp.net/C# and write the data obtained into a mysql table.The excel sheet contains something around 50 columns and 2000 records.I am able to read the data from the excel sheet and store it in a dataset.I am using the following code to write the data into mysql table.

for (int i = 1; i <= myDataSet1.Tables[0].Rows.Count - 1; i++)
        {           
            MySqlCommand cmd = new MySqlCommand();
            for (int j = 0; j <= myDataSet1.Tables[0].Columns.Count - 1; j++)
            {
                paramset[j] = myDataSet1.Tables[0].Rows[i][j].ToString();
                cmd.Parameters.AddWithValue("val" + j, paramset[j]);
            }
              cmd.CommandText = "Insert into faqimport values(val0,val1,val2,val3,val4,val5,val6,val7,val8,val9,val10,val11,val12,val13,val14,val15,val16,val17,val18,val19,val20,val21,val22,val23,val24,val25,val26,val27,val28,val29,val30,val31,val32,val33,val34,val35,val36,val37,val38,val39,val40,val41,val42)";
         cmd.Connection=con;
            cmd.CommandType = CommandType.Text;
        int x=cmd.ExecuteNonQuery;
        }

When I try to run the above code I am getting ‘Unknown column ‘val0’ in ‘field list” error.I understand that i am manually creating the parameters val0,val1,val2…..instead I am creating them dynamically using the integer ‘j’.But I do not want to create around 50 parameters to insert data into the database table.

Could someone please tell me if there is a wayaround this?

Also is there a way i can get the column datatypes from the excel sheet in order to create a new table in mysql with the columns in the excel sheet?

  • 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-15T01:19:09+00:00Added an answer on May 15, 2026 at 1:19 am

    I think the “val0, val1..” are not getting replaced with the parameters you are adding to the command. Could it be because you are not prefixing them with an ‘@’? (“@val0, @val1..”)
    Same for the AddWithValue()

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

Sidebar

Ask A Question

Stats

  • Questions 434k
  • Answers 434k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The code at datatables.net should work on Ubuntu browsers. You… May 15, 2026 at 3:10 pm
  • Editorial Team
    Editorial Team added an answer The client side code is generated by RIA Services. To… May 15, 2026 at 3:10 pm
  • Editorial Team
    Editorial Team added an answer You can use android.net.Proxy class to get info about Proxy… May 15, 2026 at 3:10 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.