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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:46:46+00:00 2026-06-11T12:46:46+00:00

I have now a problem with a very old system of ours. (! It

  • 0

I have now a problem with a very old system of ours. (!It is more then 7 years old and I have no budget and resources to make bigger change in the structure, so the decision to improve the old logic as many as we can.!)

We have an own written gridcontrol. Basically it is like a normal ASP.NET grid, you can add, change, delete elements.

The problem is that the grid has a BindGrid() method, where for further usage, the rows of the datasource table copied into a DataRow[]. I need to keep the DataRow[], but I would like to implement the best way to copy the source from the the table into the array.

The current solution:

DataRow[] rows = DataSource.Select("1=1", SortOrderString);

As I experienced so far, if I need to get a specified sort, that could be the best way (I’m also interested if it has a quicker way or not.)

BUT there are some simplified pages, where the SortOrder is not needed.

So I could make two method one for the sort order and one for without.
The real problem is the second one:

 DataRow[] rows = DataSource.Select("1=1");

Because it is very slow. I made some test and it is kind of 15 times slower then the CopyTo() solution:

DataRow[] rows = new DataRow[DataSource.Rows.Count];
DataSource.Rows.CopyTo(rows,0);

I would like to use the faster way, BUT when I made the tests some old function simply crashed. It seems, there is an other difference, what I only noticed now:
The Select() gets the rows like the RowChanges are accepted.

So if I deleted a row, and I do not use the AcceptRowChanges() (I can’t do that unfortunately), then with Select("1=1") the row is in the DataSource but not in the DataRow[].

With a simple .CopyTo() the row is there, and that is a bad news for me.

My questions are:

1) Is the Select(“1=1”) the best way to get the rows by the RowChanges? (I doubt a bit, because it is like 6 year old part)

2) And if 1) is not, is it possible to achieve a faster way with the same result than the .Select(“1=1”) ?

UPDATE:

Here is a very basic test app, what I used for speedtesting:

DataTable dt = new DataTable("Test");

dt.Columns.Add("Id", typeof (int));
dt.Columns.Add("Name", typeof(string));

for (int i = 0; i < 10000; i++)
{
    DataRow row = dt.NewRow();
    row["ID"] = i;
    row["Name"] = "Name" + i;
    dt.Rows.Add(row);
}

dt.AcceptChanges();
DateTime start = DateTime.Now;

DataRow[] rows = dt.Select();

/*DataRow[] rows = new DataRow[dt.Rows.Count];
dt.Rows.CopyTo(rows,0);*/

Console.WriteLine(DateTime.Now - start);
  • 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-11T12:46:47+00:00Added an answer on June 11, 2026 at 12:46 pm

    You can call Select without an argument: DataRow[] allRows = DataSource.Select(); That would be for sure more efficient than "1=1" since that applies a pointless RowFilter.

    Another way is using Linq-To-DataSet to order and filter the DataTable. That isn’t more efficient but more readable and maintainable.

    I have yet no example or measurement, but it is obvious that a RowFilter with "1=1" is more expensive than none. Select is implemented in this way:

    public Select(DataTable table, string filterExpression, string sort, DataViewRowState recordStates)
    {
        this.table = table;
        this.IndexFields = table.ParseSortString(sort);
        this.indexDesc = Select.ConvertIndexFieldtoIndexDesc(this.IndexFields);
        // following would be omitted if you would use DataSource.Select() without "1=1"
        if (filterExpression != null && filterExpression.Length > 0)
        {
            this.rowFilter = new DataExpression(this.table, filterExpression);
            this.expression = this.rowFilter.ExpressionNode;
        }
        this.recordStates = recordStates;
    }
    

    If you want to be able to select also the rows that are currently not accepted, you can use the overload of Select:

    DataRow[] allRows = DataSource.Select("", "", DataViewRowState.CurrentRows | DataViewRowState.Deleted);
    

    This will select all rows inclusive the rows that are deleted even if AcceptChanges was not called yet.

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

Sidebar

Related Questions

I have this very old intranet system, which was implemented I think 6-8 years
I have a very old application that now needs to be friendly to Windows
We work with very old legacy system implemented in C++ with VC6 compiler. Now
I have the following problem. My PC is very old and it has a
This problem has bugged me so many times and i have now decided to
I'm onto problem 245 now but have hit some problems. I've done some work
Well i have a web page hosted in a IIS 7.0 now the problem
I have a dynamic list code that works just fine. My only problem now
I have a problem right now with CodeIgniter : I use the REST Controller
I have encountered a problem twice now whereby a producer thread produces N work

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.