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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:38:30+00:00 2026-06-12T01:38:30+00:00

I have a dataset with three tables in it. I want to compare a

  • 0

I have a dataset with three tables in it. I want to compare a column item from one table against column items from the other two but to do this I am using nested foreach loops. The code is returning way more data than it should be so I have a feeling I messed something up; also I’m sure there is a better/cleaner way to do this, feel free to let me know.

foreach (DataRow row in dataSet.Tables["Taxonomy"].Rows)
            {
                var projectTypes = row["ProjectType"].ToString();
                var tier3 = row["Tier3Project"].ToString();
                if (tier3.Equals(""))
                    tier3 = "null";
                Console.WriteLine(projectTypes);

                foreach (DataRow dRow in dataSet.Tables["DefaultEventTypes"].Rows)
                {
                    var name = dRow["name"].ToString();
                    if (name.Equals(""))
                        name = "null";

                    /****** Begin Comparisons ******/
                    if (projectTypes.Trim().ToLower().Equals(name.Trim().ToLower()))
                    {
                        foreach (DataRow sRow in dataSet.Tables["ScheduleEvents"].Rows)
                        {
                            var nameShort = sRow["nameShort"].ToString();

                            /****** Compare to ScheduleEvent ******/
                            if (projectTypes.Trim().ToLower().Equals(nameShort.Trim().ToLower()))
                            {
                                //Update both DefaultEventType and ScheduleEvent
                                Console.WriteLine(projectTypes + "     " + name + "     " + tier3);
                                counter++;
                            }
                            else
                            {

                            }
                        }
                    }
                    else
                    {
                        foreach (DataRow sRow in dataSet.Tables["ScheduleEvents"].Rows)
                        {
                            var nameShort = sRow["nameShort"].ToString();

                            /****** Compare to ScheduleEvent ******/
                            if (projectTypes.Trim().ToLower().Equals(nameShort.Trim().ToLower()))
                            {
                                //Update ScheduleEvent
                            }
                        }
                    }
                    /****** End Comparisons ******/
                }
            }

I can clarify if needed, thanks!

Edit:

I want to pull an item from table ‘Taxonomy’ and then compare it to every row in table ‘DefaultEventTypes’. If there is a match, I then want to compare the ‘Taxonomy’ item to every row in ‘ScheduleEvent’.

Eventually I want to add in update statements to change matching items to a new name and save the tables back to the database.

It seems to be doing comparisons but the number of values it’s returning is far too large.

  • 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-12T01:38:31+00:00Added an answer on June 12, 2026 at 1:38 am
    dataSet.Tables["Table1"].AsEnumerable().Select(r => r.Field<string>("Field1")).Intersect(
    dataSet.Tables["Table2"].AsEnumerable().Select(r => r.Field<string>("Field2"))).Intersect(
    dataSet.Tables["Table3"].AsEnumerable().Select(r => r.Field<string>("Field3")));
    

    Something like that…didn’t test this, though

    PS: this should return you a set of values, that are present in all 3 tables in respective columns.

    Answer to comment:
    Well, you have enough information to update things you want.

    var valuesThatRepeat = GetWhatYouNeedUsingCodeAbove();
    foreach (var value in valuesThatRepeat)
    {
        var rows = dataSet.Tables["Table2"].AsEnumerable().Where(r => ((string)r["Column2"]).Equals(value));            
        foreach(var row in rows)
        {
            row["Column2"] = (string)r["Column2"] + "of_row_with_id_" + (string)r["Id"]; // update the value with whatever you want
        }
    }
    

    This example will update all the values in the second table so that they are no longer similar to those in other 2 tables. PS: again, didn’t test that. syntax error are possible

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

Sidebar

Related Questions

I have a dataset with multiple tables. One table in particular has one record
I have three tables from a dataset ds. var test0 = from a in
I have a DataSet with multiple tables (distinct schema). I want to generate table
I have a Dataset that contains tables from a university database, two(actually more) of
I've got a bunch of strongly typed DataSet that each have two tables. One
I have a dataset with one datatable. Now I want to set a filter
I'm using table adapters and datasets in .NET (version 2.0). I have two tables
I have a dataset with two tables and between these tables there is a
I have three records in my table and I want to display those records
I have two similar tables on different databases. Database1/TableA Database2/TableA I want to fetch

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.