Solved

Compute method in dataset

Posted on 2008-10-09
7
480 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:tedbilly
Comment Utility
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 20 total points
Comment Utility
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
Comment Utility
no i want to use the top 10 in the output data not to the original table
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 51

Accepted Solution

by:
tedbilly earned 30 total points
Comment Utility
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
Comment Utility
Looping method hmmm, i think this will take time specially if the records are too big
0
 
LVL 51

Expert Comment

by:tedbilly
Comment Utility
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:tedbilly
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how the fundamental information of how to create a table.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now