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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:04:54+00:00 2026-05-29T08:04:54+00:00

In C# (.NET 3.5) I’ve filled a DataTable with rows from my database. In

  • 0

In C# (.NET 3.5) I’ve filled a DataTable with rows from my database. In this DataTable there are about 100 to 200 DataRows. I have to loop through this DataTable to check if the data is correct and I use 27 check-methods. First I’ve tried to pass the DataTable to each method and loop it. In my second attempt I’ve looped the DataTable once and passed the DataRow to each method. Afterwards I’ve benchmarked these two methods and the first method was faster than the second?

Looping the DataTable 27 times took 13 seconds.

Looping the DataTable 1 time took 18 seconds.

So what’s the explanation for this? And what is really the fastest way to loop through a DataTable to check it’s data?

Note: the benchmark was started right before I started the check-methods to exclude connection speed to the database.

First method:

private void check()
{
    System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
    sw.Start();

    checkStamnr();
    checkVoornaam();
    checkGebDatum();
    ...

    sw.Stop();
    sw.Reset();
}

private void checkStamnr()
{
    foreach (DataRow dr in dtIdentificatieRecords.Rows)
    {
        if (dr["STAMNRVOL"] == null || dr["STAMNRVOL"].GetType() == typeof(DBNull) || dr["STAMNRVOL"].equals(""))
        {
            DatabankFout df = new DatabankFout("Stamnummer is leeg.");
            listDBFouten.Add(df);
        }
    }
}

Second method

private void check()
{
    System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
    sw.Start();

    foreach (DataRow dr in dtIdentificatieRecords.Rows)
    {
        checkStamnr(dr);
        checkVoornaam(dr);
        checkGebDatum(dr);
        ...
    }

    sw.Stop();
    sw.Reset();
}

private void checkStamnr(DataRow dr)
{
    if (dr["STAMNRVOL"] == null || dr["STAMNRVOL"].GetType() == typeof(DBNull) || dr["STAMNRVOL"].equals(""))
    {
        DatabankFout df = new DatabankFout("Stamnummer is leeg.");
        listDBFouten.Add(df);
    }
}

Class DatabankFout on request:

public class DatabankFout
{
    public DatabankFout(string reden, bool rood)
    {
        this.reden = reden;
        this.rood = rood;
    }
    public DatabankFout(string reden) : this(reden, false)
    {
    }

    public string reden { get; set; }
    public bool rood { get; set; }
}
  • 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-29T08:04:55+00:00Added an answer on May 29, 2026 at 8:04 am

    I would say that a run-time difference of 25% in one run with so few items is not significant.
    Run your test at least 10 times for 10000 items in the list.
    If the first is still faster, I will have something to think about.

    The main part of the time probably comes from creating the DatabankFout, which might be a database connection.

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

Sidebar

Related Questions

Net MVC 3 web application. I generated my models from an existing database using
net MVC Web Application. I have a database where i have made my model,
.NET, Java and other high level database API's in various language often provide techniques
.NET developers out there! Need your opinion here! I am now using Visual Assist
.NET balanced group regexes make my head explode. I've got this string i'm trying
.NET 3.5, C# I have a web app with a search feature. Some of
.NET/MVC3 newbie, so please bear with me! I've searched for this answer all over
.NET newbie alert Using Visual C# 2008 Express Edition I have accidentally created a
.NET 4, EF 4 I have two related entities, Order and OrderLine. Order contains
net ajax app. I have one modelpopup that shows a IFrame and inside Iframe

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.