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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:11:45+00:00 2026-05-26T22:11:45+00:00

I have 2 sets of data from different systems. About 20,000 records a piece.

  • 0

I have 2 sets of data from different systems. About 20,000 records a piece. One set of data is a List<Objects>, the other is a RecordSet from a system I have no control over (I can only ask for records and receive the recordset).

I need to merge data between the 2, matching on a key that exists in both lists, by putting some data from the Recordset into the matching object structure. The nested loop I’ve tried is entirely too slow.

Is there a fast way to get the match and move on to the next object?

EDIT: EXISTING CODE

This is a very basic nested loop

results = _sr.SearchLst(ut.ToString(), searchSettings);

foreach (BL.Packet ePacket in eList) {

    for (Int32 j = 0; j < results.Rows.Length; j++) {

        String acckey = results.Rows[0].Data.GetValue(1).ToString();
        String taskname = results.Rows[0].Data.GetValue(2).ToString();

        if (acckey == ePacket.RecKey.ToString()) {
            ePacket.prop1 = taskname;
            ePacket.prop2 = acckey;
        }
    }
}

I did also look at Linq, but couldn’t get a grasp of how the two would go together…I’m not sure Linq would be faster anyway.

SOLUTION:

Here’s basically what I ended up doing.

//move object from list to dictionary
var dict = eList.Cast<BaseObj>().ToDictionary(o => o.RecKey, o => o);

results = _sr.SearchLst(ut.ToString(), searchSettings);
if (results.Rows.Length > 0) {

    //loop through all rows in recordset
    for (Int32 j = 0; j < results.Rows.Length; j++) {
        id = Convert.ToInt32(results.Rows[j].Data.GetValue(1)); 
        taskname = results.Rows[j].Data.GetValue(2).ToString();

        if (dict.ContainsKey(id)) {
            //recordset id found in dictionary, so grab taskname
            ePacket = ((BL.Packet)dict[id]);
            ePacket.prop1 = taskname;
        }
    }
}

//move dictionary back to list
List<BaseObj> eListReturn = new List<BaseObj>(dict.Values);
return eListReturn;

Thanks to everyone for the assistance!

  • 1 1 Answer
  • 3 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-26T22:11:46+00:00Added an answer on May 26, 2026 at 10:11 pm

    Use a Dictionary<TypeOfKey, SomeObject> on the list collection you have in memory, populate the dictionary using the key as key and the object as value.

    Loop over the record set. Using the dictionary you can do an O(1) lookup of the matching element, so you can eliminate the looping over the in-memory collection.

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

Sidebar

Related Questions

Have two sets of data (two tables) for patient records, one 1999-2003, the other
I have a report with multiple data-sets. Different fields from different data-sets are used
Here's a simplified version of the 3 data sets I have: Set A =
I have two types of data sets. Both are in same size. One contains
Here's my situation. I have a graph that has different sets of data being
I have a crystal report that gets its data from one stored procedure, this
I have a command Get-Testdata that retrieves test data from different sources and stores
I have three Buttons options that retrieve data from db and sets datacontext to
I have two sets of statistics generated from processing. The data from the processing
I have an application that has different data sets depending on which company 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.