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

  • Home
  • SEARCH
  • 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 8979489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:51:32+00:00 2026-06-15T19:51:32+00:00

I think at this point I’ve just looked at this code so long that

  • 0

I think at this point I’ve just looked at this code so long that the logic is getting fuzzy and I need more eyes on it.

Input is a series of controls that create a few List<> objects. Variables involved are importData, a List which contains “sarray”s, which are string[]s containing a list of field values. The Lists<> referenced for “validIndeces” and “indecesCantBeDuplicated” contain the indeces of items in importData’s sarrays that we actually need, and which ones of those can’t have a duplicate in the same field (i.e., no two company ID’s the same).

The goal here is to take importData’s string[]s, filter out the ones we don’t need in the query, execute some instruction to make them compatible with data in a certain table, and then check to ensure that no duplicates exist in a given field. If a field is indicated in “indecesCantBeDuplicated” and a match is found earlier in the importData in the same index, then it should move on to the next string[] object, otherwise add the line to the query.

Output basically comes out to a series of Insert statements in SQL, but that code is fine. Here’s where I’m stuck. Why am I not filtering out the duplicates on this?

//go through each string array in the import (i.e. each record to import)
foreach (string[] sarray in importData) {
    List<List<string>> QueryList = new List<List<string>>();
    List<string> Queriables = new List<string>();
    for (int i = 0; i < sarray.Count(); i++) {
        bool addit = true;
        if (validIndeces.Contains(i)) {
        //ensure this is one of the indeces used to import
            if (indecesCantBeDuplicated.Contains(i)) {
                // if THIS index can't have duplicate values
                foreach (string[] s2 in importData) {
                    //check each record in the import
                    foreach(string s in s2) {
                        //check each field in the record
                        if (s2.ElementAt(i) == sarray[i]) {
                            //if the field value at this index matches the one we're about to put in
                            addit = false;
                        } else {
                            addit = true;
                        }
                    }
                }
            }
            if (indecesToDelimit.Contains(i)) {
                //ensure that delimiters are added to all text field values
                sarray[i] = "'" + sarray[i] + "'";
            }

            if (addit) {
                Queriables.Add(sarray[i]);
            }
        }
    }
}
  • 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-06-15T19:51:33+00:00Added an answer on June 15, 2026 at 7:51 pm

    You have to break out of your foreach when you detect an addit == false. Otherwise, it will just be set to true again on the next loop iteration.

    {
        addit = false;
        break;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think this is easily explained by looking at code, so I'm posting a
I think this code For Each file in filecoll Ext = UCase(Right(File.Path, 3)) If
I think this code should be fine but Static Analyzer doesn't like it. I
I think this is more of my lack of understanding the intricacy of Types
I think this could be a very easy question for you. But I have
(I think this is a pretty basic question on OOP, but unfortunately I wasn't
I think this is a simple and a silly question. I have included a
I think this is nearly impossible or very tricky. I'm using CriteriaBuilder, JPA 2.0,
I think this is a pretty straightforward problem but... var outerHeight = $('.profile').outerHeight(); $(#total-height).text(outerHeight
I think this is mostly because I'm new to PHP OOP, but I have

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.