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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:37:34+00:00 2026-06-06T13:37:34+00:00

I have a method somewhat similar to the one written bellow(this is just a

  • 0

I have a method somewhat similar to the one written bellow(this is just a pseudo-code I am working in C#):

function GenerateChart(DataTable dt)
{
    DataTable dtChartTable = dt;
    dtChartTable.DefaultView.Sort = "SomeColumnName";
    //remaining functionality
}

what this above code does is it also sorts the records in dt. I am not getting why it is doing so. Just as a note: this function is called from two different places. at one place I am sending a Datatable object and at the other the Datatable is directly refered from the one stored in session.

  • 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-06T13:37:36+00:00Added an answer on June 6, 2026 at 1:37 pm

    That’s right.
    You are setting the dtChartTable variable to the same memory represented by the dt variable.
    So, sorting the dtChartTable affects the same DefaultView property used by the second .

    If you don’t want this behavior you could create a copy of dt using

    DataTable dtChartTable = dt.Copy();
    

    but this is costly because in this way every datarow is duplicated.
    Another possibility is creating a new DataView

    DataView view = new DataView(dt);
    view.Sort = "SomeColumnName";  
    ......
    

    this doesn’t affect the original dt.DefaultView and you can process your datarowview from this new DataView

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

Sidebar

Related Questions

I have this method that changes an larger image source on click. I need
My question is somewhat related to this one: How does a generic constraint prevent
Currently I have code like the following (simplified somewhat). Eventually, I've added more and
I have a somewhat special use case, where I'd like to create a method
Currently I have this code in my UIViewController: //Cocos2D methods -(id) init { if((self=[super
We have a method that accesses a network share. This method works fine when
My issue is somewhat similar to this SO question. However, since my implementation is
I have method in a class that I need to make sure is only
I've got some 3rd party beans that have method signatures that fit quite well
I create small application which is media player. I have method where I have

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.