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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:15:04+00:00 2026-05-16T21:15:04+00:00

I am currently using one button for inserting/updating content within a table. It then

  • 0

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.

Here is the code fired after the button’s OnClick:

if (ExcelDDL.SelectedValue == "Time Points" && 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 > 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('>');
                        int insertH = Convert.ToInt32(hta.InsertHandicapRow(newRoute,noHTML[2]));
                    }
                    var sequence = Convert.ToString(row["Sequence"]);
                    var origID = -1;

                    if (GetTPoints.Rows.Count > 0)
                    {
                        origID = Convert.ToInt32(GetTPoints.Rows[i]["TPointsID"]);
                        var GetID = (SEPTA_DS.TimePointsTBLDataTable)tpta.GetDataByID(origID);
                        if (GetID.Rows.Count < 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++;
                }
            }

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.

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

alt text

This is the table after reuploading the CSV with data already existing within the table:

alt text

I am also getting this error when updating There is no row at position 2230.
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.

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

  • 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-16T21:15:04+00:00Added an answer on May 16, 2026 at 9:15 pm

    Is your TPointsID column, a auto-generated number? If so, since you are skipping the empty row, some referential integrity problem might be occuring,because of empty data in the skipped rows in the database.


    From the error : There is no row at position 2230 , it is also understood that, because of the skipping you might be trying to access some non existent row in the datatable.

    Also, if possible consider using the ADO.NET DataAdapter which has got the CRUD operation capability. You can find more about it at : http://support.microsoft.com/kb/308507

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

Sidebar

Related Questions

I'm using (GNU) Make in my project. I'm currently putting one makefile per directory
In sybase, using a cursor can one delete the currently referenced row? If so
I am currently using the following command to upload my site content: scp -r
Currently using System.Web.UI.WebControls.FileUpload wrapped in our own control. We have licenses for Telerik. I
Im currently using vs2008 with asp.net mvc framework for web development. Im missing a
I'm currently using VS2005 Profesional and .NET 2.0, and since our project is rather
I am currently using Windows Server 2008 Standard and have several Hyper V machines.
I'm currently using the awesome attachment-fu plugin for a Rails app, but as a
My company is currently using Sage MAS as their ERP system. While integrating our
I'm currently using DPack as this adds a Collapse All Projects option to the

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.