Solved

Compute method in dataset

Posted on 2008-10-09
7
483 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 20 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 51

Accepted Solution

by:
Ted Bouskill earned 30 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

896 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

13 Experts available now in Live!

Get 1:1 Help Now