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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:50:34+00:00 2026-05-24T08:50:34+00:00

i am importing data from excel to sqlserver..i have filled the dataset with the

  • 0

i am importing data from excel to sqlserver..i have filled the dataset with the data in excel sheet..and now iam manipulating data within dataset like removing empty rows from sheet.I have written this code for eliminating empty rows but it is showing me an error that”there is no row at 18 position.” And also the count of empty rows is 11.This is the code snippet:

    public DataSet GetExcelData()
    {
        DataTable ExcelTable = new DataTable();
        List<int> rowToRemove = new List<int>();
        //DataRow ExcelRow = new DataRow();

        foreach (DataRow excelrow in dsExcel.Tables[0].Rows)
        {
            bool IsEmpty = false;
            foreach (object item in excelrow.ItemArray)
            {
                if (String.IsNullOrEmpty(item.ToString())) 
                {
                     IsEmpty = true;
                     break;

                }                  
                else
                {
                    IsEmpty = false;

                }
            }
            if (IsEmpty)
            { 
                **rowToRemove.Add((dsExcel.Tables[0].Rows.IndexOf(excelrow)));**
            }

        }

        for (int i = 0; i < rowToRemove.Count; i++)
        {
            **dsExcel.Tables[0].Rows.RemoveAt(rowToRemove[i]);**
            //dsExcel.Tables[0].Rows.Remove(rowNumber); ; ;
        }
        return dsExcel;

    }

the lines which i have marked over there i am getting problem.it is not taking proper rows.
I have placed a breakpoint and also checked..it showed in this manner:

[0] 0

[1] 2

[2] 4

[3] 6

[4] 8

[5] 10

[6] 12

[7] 14

[8] 16

[9] 18

[10] 20

it is counting the rows from 0 position..which is not there at all.and it is not taking the empty row at 22 position..
please say me what i need to do 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-24T08:50:36+00:00Added an answer on May 24, 2026 at 8:50 am

    As soon as you removed the first item from the list all the following indexes are off.
    You might want to remove the last one first:

    for (int i = rowToRemove.Count - 1; i >= 0; --i)
    {
        dsExcel.Tables[0].Rows.RemoveAt(rowToRemove[i]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am currently working on importing data from excel sheet to sql server.i have
I am importing massive amounts of data from Excel that have various table layouts.
I'm importing data from an Excel sheet on to a DataTable using the following
i am preparing myself for importing data from excel sheet to sql server 2005.I
I am working on importing data from an Excel sheet to database. The Excel
So, there have been several posts here about importing and saving data from an
I have a web form used for importing data from a CSV file. It
I have an excel spread sheet (well, hundreds of them) which I need importing
I had used JExcel API for importing Data's from Excel,for using JExcel , I
My app generates SSIS packages for importing data from Excel files. This is done

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.