Compute method in dataset

I always use compute function to calculate data in some columns in the output datatable variable, so is there a way i can use if i want for example the sum of the top 10 rows in datatable, can i use compute, i donot want to return to the original table
Thanx
ashraf_tAsked:
Who is Participating?
 
Ted BouskillSenior Software DeveloperCommented:
Sorry but I'm more comfortable with C#
DataTable outputTable = SourceTable.Clone();
for(int i=0;i<10;i++)
  outputTable.ImportRow(SourceTable.Rows[i]);

Open in new window

0
 
Ted BouskillSenior Software DeveloperCommented:
The DataSet object actually uses a substantial amount of overhead (memory and CPU)  An aggregate operation can even consume more resources.  I would strongly recommend you do this in the SQL database.
0
 
CodeCruiserCommented:
If you still prefer to do it in the memory then use the select function to select the top 10 rows and then use the compute.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
ashraf_tAuthor Commented:
no i want to use the top 10 in the output data not to the original table
0
 
ashraf_tAuthor Commented:
Looping method hmmm, i think this will take time specially if the records are too big
0
 
Ted BouskillSenior Software DeveloperCommented:
It's either that or do it in the SQL server.  You don't have any other choices.  The Select() method in the DataTable doesn't support aggregate functions.
0
 
Ted BouskillSenior Software DeveloperCommented:
I manage 5 software developers building web applications.  I wouldn't allow them to do this in a dataset at all.  I'm just trying to answer your question, I don't agree with the strategy.

If you are worried about performance, minimize or avoid using the dataset and use the SqlDataReader instead and define your own collection.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.