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 currently using a select statement with one column as DATEPART(hh, CallTime) AS Hour
I am currently using c(module_name) to build my Erlang files one by one. How
I am currently using two .htaccess files for my website: one is the development
I am currently writing a program using Weka that builds a model (using one
We are currently using JDeveloper to build our production EARs. One problem with this
Currently I am using a post-build event command line similar to this one: xcopy
Currently I'm using a small search and replace snippet for one of my WordPress
I'm currently learning Python using Zelle's Introductory text, and I'm trying to recreate one
We currently have one publisher and four subscribers using merge replication. Due to a
I'm using Rails 3.2, Carrierwave and simple_form. Currently, everything is working fine with one

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.