C# Updating Data Issue
<p>I am currently using one button for inserting/updating content within a table. It then takes the uploaded CSV and inserts or updates it into a data table depending on whether the row exists or not.</p>

<p>Here is the code fired after the button's OnClick:</p>

<pre><code>if (ExcelDDL.SelectedValue == "Time Points" &amp;&amp; fileName == "TimePoints.csv")
            {
                var GetTPoints = (SEPTA_DS.TimePointsTBLDataTable)tpta.GetDataByCategory(CategoryDDL.SelectedItem.ToString());

                //Loop through each row and insert into database
                int i = 0;
                foreach (DataRow row in TempRouteDataTable.Rows)
                {
                    //Gather column headers
                    var category = Convert.ToString(CategoryDDL.SelectedItem);
                    var agency = Convert.ToString(row["Agency"]);
                    if (agency == null || agency == "")
                    {
                        //If row is empty skip it entirely
                        goto skipped;
                    }
                    var route = Convert.ToString(row["Route"]);
                    var GetRShortName = (SEPTA_DS.RoutesTBLDataTable)rta.GetDataByRouteID(route);
                    var newRoute = "";
                    if (GetRShortName.Rows.Count &gt; 0)
                    {
                        newRoute = Convert.ToString(GetRShortName.Rows[0]["route_short_name"]);
                    }

                    var direction = Convert.ToString(row["Direction"]);
                    var serviceKey = Convert.ToString(row["Service Key"]);
                    var language = Convert.ToString(row["Language"]);
                    var stopID = Convert.ToString(row["Stop ID"]);
                    var stopName = Convert.ToString(row["Stop Name"]);

                    if (stopName.Contains("accessible"))
                    {
                        string[] noHTML = stopName.Split('&gt;');
                        int insertH = Convert.ToInt32(hta.InsertHandicapRow(newRoute,noHTML[2]));
                    }
                    var sequence = Convert.ToString(row["Sequence"]);
                    var origID = -1;

                    if (GetTPoints.Rows.Count &gt; 0)
                    {
                        origID = Convert.ToInt32(GetTPoints.Rows[i]["TPointsID"]);
                        var GetID = (SEPTA_DS.TimePointsTBLDataTable)tpta.GetDataByID(origID);
                        if (GetID.Rows.Count &lt; 1)
                        {
                            origID = -1;
                        }
                    }

                    if (origID == -1)
                    {
                        int insertData = Convert.ToInt32(tpta.InsertTimePoints(category, agency, newRoute, direction, serviceKey, language, stopID, stopName, sequence));
                    }
                    else
                    {
                        int updateData = Convert.ToInt32(tpta.UpdateTimePoints(category, agency, newRoute, direction, serviceKey, language, stopID, stopName, sequence, origID));
                    }
                    skipped:
                    i++;
                }
            }
</code></pre>

<p>You can see how I check whether to insert or update around the bottom. I am using this method across other sections of this program and it works just fine. But in this case it is distorting my datatable immensely and I can't figure out why.</p>

<p>This is the bottom part of my table after inserting [no items currently within the database]:</p>

<p><img src="http://i.stack.imgur.com/9X7ys.jpg" alt="alt text"></p>

<p>This is the table after reuploading the CSV with data already existing within the table:</p>

<p><img src="http://i.stack.imgur.com/Kzau5.jpg" alt="alt text"></p>

<p>I am also getting this error when updating <code>There is no row at position 2230.</code>
What is going wrong in the code to cause this huge shift? I am just checking to see if the ID exists and if it does update rather than insert.</p>

<p>Also the reason i am using <code>goto</code> is because there are blank rows in the document that need to be skipped.</p>
