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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:04:37+00:00 2026-06-12T02:04:37+00:00

Basically I have a DataTable with a rows containing part numbers and a couple

  • 0

Basically I have a DataTable with a rows containing part numbers and a couple of columns that contain information on those parts.

In order to compare those infos with the data we have in the database, I have determined I have one of two options.

Option 1 – Loop through each row and SELECT the data

void CompareData(DataTable dt) {
    foreach (DataRow entry in dt.Rows) {
        //select that row
        DataRow dbEntry = ExecuteQuery("SELECT * FROM Parts WHERE partno='" + entry["partno"] + "'").Rows[0];
        if (dbEntry["info1"] == entry["info1"]) {
            //do something
        } else {
            //do something
        }
    }
}

Option 2 – SELECT all data at once and compare via loops

void CompareData(DataTable dt, string[] parts) {
    DataTable dbEntries = ExecuteQuery("SELECT * FROM Parts WHERE partno IN('" + String.Join(parts, "','") + "')");
    foreach (DataRow entry in dt.Rows) {
        foreach (DataRow dbEntry in dt.Rows) {
            if (dbEntry["partno"] == entry["partno"]) {
                if (dbEntry["info1"] == entry["info1"]) {
                    //do something
                } else {
                    //do something
                }
            }
        }
    }
}

They both seem pretty inefficient, so I’m not really sure what to do. Would LINQ speed this process up? I’ve never really used it but just browsing around it looks like something that could help.

  • 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-12T02:04:38+00:00Added an answer on June 12, 2026 at 2:04 am

    Make as few DB calls as possible. You’ll be more efficient 99.9% of the time. (general rule to code by)

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

Sidebar

Related Questions

Well. I have a DataTable with multiple columns and multiple rows. I want to
I basically have a program that filters records from one excel file to another
I basically have 7 select statements that I need to have the results output
Basically i have a query string that when i hardcode in the catalogue value
This is tricky to explain. We have a DataTable that contains a user configurable
I need some help with a linq query. Basically, I have a datatable with
i have the following code that queries a db and populates a datatable. private
I have a DataTable containing a list of Id's I get from the DB.
I have a JSF page that is basically a create form. The form consists
I have a SQL class that connects to the DB and retreives a DataTable.

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.