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.
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
but this is costly because in this way every datarow is duplicated.
Another possibility is creating a new DataView
this doesn’t affect the original dt.DefaultView and you can process your datarowview from this new DataView