Creating a DataTable from another DataTable

  • Thread starter Thread starter nltoft
  • Start date Start date
N

nltoft

I would like to create a DataTable from another DataTable so that I can sum
certain fields using a GROUP BY clause. Is this possible?

For example:
Table1:
Employee, Department, Hours (these are the field names)
Emp1, Dept1, 8 (first row of data)
Emp1, Dept1, 8
Emp1, Dept2, 8
Emp1, Dept1, 8
Emp1, Dept2, 8
Emp2, etc.

I want to create a Table2 from Table1 using:
SELECT Employee, Department, SUM(Hours) as TotHrs FROM Table1
GROUP BY Employee, Department

So for Emp1, Table2 would contain two rows:
Employee, Department, TotHrs
Emp1, Dept1, 24
Emp1, Dept2, 16

If this is not possible, is there some way to achieve the same effect?
 
Hi,

The select has definitly been a reason why LINQ to SQL is made. Some expect
the Select is a kind of mini SQL, it is not.

Have simple a look at Linq to SQL for the program language you are using.

A select returns a collection of datarows, by importing them again, and then
using one of the overloaded methods of the dataview will probably give you
the result you want, but this can better be done with Linq to SQL

Cor
 
Hi,

There are several solutions:
- check out QueryADataset library (http://www.queryadataset.com/) to perform
SQL commands on in-memory table
- use Linq to Dataset to group the data from in-memory table
- execute query on server and avoid client side code
....
 
Thank you and Miha very much. Since you are an MVP, could you please direct
me to which forum I should ask a question about a project building
unexpectedly within one of my solutions? I've tried 3 forums, but no response
in any of them yet (Project management, C sharp general discussion, Visual
Studio .NET general discussion).
 
As it is about C# then the most general newsgroup despite its name is

microsoft.public.dotnet.languages.csharp
 
Ah, you're an MVP, too. Since you asked, :), and I did already post this in
the C# forum with no response:

I have a .NET C# solution with 6 projects as follows:

Project A (DLL) not dependent on any other projects
Project B (DLL) dependent on Project A
Project C (DLL) dependent on Project A and B
Project D (DLL) dependent on Project A and B
Project E (EXE) dependent on Project A, B, C, D
Project F (setup project)

I checked all project dependencies by right clicking the projects in the
Solution Explorer and they look good. However, when I make a change to a
class in Project D only, Projects B and C rebuild and I expect them not to.
Project A does not rebuild, as expected. Projects E and F do rebuild, but
that is also expected.

Can anyone explain this? I do not want Projects B and C to change timestamp
if there is no reason for them to do so. I do not want to be forced to give
them new build numbers when nothing has really changed.
 
Hi,

How are projects dependant? Through references or just through
configuration?
I created a sample like you've described and linked the projects through
references (no manual dependencies were added) and it behaves like you or I
would expect.
 
Back
Top