There is no row at position 18
<p>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:</p>

<pre><code>    public DataSet GetExcelData()
    {
        DataTable ExcelTable = new DataTable();
        List&lt;int&gt; rowToRemove = new List&lt;int&gt;();
        //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 &lt; rowToRemove.Count; i++)
        {
            **dsExcel.Tables[0].Rows.RemoveAt(rowToRemove[i]);**
            //dsExcel.Tables[0].Rows.Remove(rowNumber); ; ;
        }
        return dsExcel;

    }
</code></pre>

<p>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:</p>

<p>[0] 0</p>

<p>[1] 2</p>

<p>[2] 4</p>

<p>[3] 6</p>

<p>[4] 8</p>

<p>[5] 10</p>

<p>[6] 12</p>

<p>[7] 14</p>

<p>[8] 16</p>

<p>[9] 18</p>

<p>[10] 20</p>

<p>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.</p>
