Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 495
  • Last Modified:

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
0
ashraf_t
Asked:
ashraf_t
  • 4
  • 2
2 Solutions
 
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
 
ashraf_tAuthor Commented:
no i want to use the top 10 in the output data not to the original table
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now