Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Compute method in dataset

Posted on 2008-10-09
7
Medium Priority
?
493 Views
Last Modified: 2012-05-05
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
Comment
Question by:ashraf_t
  • 4
  • 2
7 Comments
 
LVL 51

Expert Comment

by:Ted Bouskill
ID: 22684389
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
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 60 total points
ID: 22685078
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
 

Author Comment

by:ashraf_t
ID: 22691632
no i want to use the top 10 in the output data not to the original table
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 51

Accepted Solution

by:
Ted Bouskill earned 90 total points
ID: 22692590
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
 

Author Comment

by:ashraf_t
ID: 22694411
Looping method hmmm, i think this will take time specially if the records are too big
0
 
LVL 51

Expert Comment

by:Ted Bouskill
ID: 22694426
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
 
LVL 51

Expert Comment

by:Ted Bouskill
ID: 22694436
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question