LINQ: How to exclude data columns from DataTable.ItemArray query?

Given a collection of data rows, IEnumerable of type DataRow, how can I query the collection so as to compute the Sum all the values in the collection (i.e. all the values of all the columns in all the rows) with the exception of two specific columns? I know only two columns prior to run time and those are the two I want to exclude. All the others I want included in the sum.

There is a extension method which will give me a specific field, e.g. Field<T>("Foo") but what I really need is the ability to say sum all the fields except field X, Y and Z.

-------------Problems Reply------------

You can use more LINQ:

DataColumn[] unwantedColumns = { table.Column1, ... };

var sum = table.Columns.Cast<DataColumn>()
.Select(c => row.Field<int>(c))

I don't think you can modify the columns a DataRow has. You can modify the columns of a DataTable though.

Category:wpf Views:0 Time:2011-06-19

Related post

  • problem in date column with hibernate hql query 2011-04-29

    i hav a hql gets the data used between two dates..i wriiten a query like this from com.cod.model.Billing where datecolumn between '2011-4-4' and '2011-4-20' but i didn't get any results from this query ..i checked out this query in mysql wi

  • Linq and comparing two date columns 2009-06-03

    I get a notsupportedexception when i run the following linq query. Any ideas how to resove it var declines = from d in _Db.DeclinedSettlementSet where d.STATUS == Status.REPORTED && d.ADD_DATE < d.EDIT_DATE.AddDays(-3) --------------Soluti

  • Daterange picker with datatables, filter date column 2012-03-19

    Im using the daterangepicker plugin from the followinng link: It is working fine within itself but i want to incorporate this within datatables plugin

  • Is it a good idea to index a date column in descending order? 2011-06-20

    In most of the tables having date column, we "would generally" query for the recent information. Is it a good idea to index a date column "generally" in descending order? --------------Solutions------------- Not familiar with Oracle's internals, but

  • Extract a full timestamp (date included) from a Select query; Oracle 2011-06-13

    So I am trying to insert multiples rows of data from one table to another. I have done this; however, I am having an issue with some of my columns, specifically my date columns. When the query returns data it is missing the time component of the date

  • Is there a way to escape and use ColdFusion query reserved words as column names in a query of query? 2012-02-13

    I'm working with a query that has a column named "Date." The original query returns okay from the database. You can output the original query, paginate the original query, get a ValueList of the Date column, etc. Query of Query <cfquery name= "Que

  • Linq on DataTable: select specific column into datatable, not whole table 2013-01-20

    I'm running a LINQ query on a datatable in c#. I want to select specific columns rather than the whole row and enter the result into a datatable. How can i do that?? My Code: public DataTable getConversions(string c_to, string p_to) { var query = fro

  • How can we copy the column data of one datatable to another,even if there is different column names of different datatable? 2010-04-07

    I have two datatables. First is DataTable NameAdressPhones = new DataTable(); with Three columns Name,Adress and PhoneNo.But I want only two columns Name and Adress data so I am copy those columns (with data) to the new datatable DataTable NameAdress

  • What is the correct date format for a Date column in YUI DataTable? 2010-04-19

    I have produced a data table. All the columns are sortable. It has a date in one column which I formatted dd/mm/yyyy hh:mm:ss . This is different from the default format as defined in the doco, but I should be able to define my own format for non-ame

  • Grouping data in a datatable based on data in a column 2011-04-06

    I have a datatable as below **Name** **Department** abc dept 1 def dept 2 ghi dept 1 jkl dept 1 mno dept 2 pqr dept 1 I need to group the data in the datatable such that all names having Department as dept1 comes togather and then all names having De

  • DataTable date columns 2011-04-23

    I am creating column in DataTable like : headerTable.Columns.Add(VendInvoice.Date, typeof(???)); I dont know how can i add just a date column, I know how to add dateTime column. --------------Solutions------------- There is no type in the BCL that im

  • LINQ - how to get next three business days excluding dates in table? 2011-07-25

    I need to find the next three available business days for a scheduling application. What is available depends upon excluded dates in a table. long as the date is not in my table and not a Saturday or Sunday, I want the next three. I'd like to

  • Sorting IQueryable date column by string value in LINQ 2011-10-17

    I am trying to sort an IQueryable object by a specific column via a string input. Calling .ToList() on the IQueryable and sorting via a list column works perfectly, however when sorting a date column, it sorts alphabetically, which is not ideal. If a

  • C# - Sorting a datatable by a date column and only binding top 10 records to grid 2011-10-31

    I bind a datatable that contains data from a SOAP call. Unfortunately, the call returns all records for whatever entity i'm fetching and there's no way at the moment of specifying number of records to return or any other argument. How could I most ef

  • jQuery DataTables - UK date column sorting 2012-03-06

    I'm using the DataTable plugin on one of my project - and the date-sorting is driving me crazy! ;) Basically, I have tables with various number of columns (between 2 and 8 columns). The date column is always the first column - I want to set UK date f

  • MVC2 - Exclude date and time column from Update method 2011-06-03

    I am tring update a record and want to exclude one column from the update, i have this field that is populated with GetDate() as a default value in sql, so when the update takes place i want this field to be left as it is, [ScaffoldColumn(false)] [Co

  • How do i extract data from a DataTable? 2009-08-28

    I have a DataTable that is filled in from an SQL query to a local database, but i don't know how to extract data from it. Main method (in test program): static void Main(string[] args) { string connectionString = "server=localhost\\SQLExpress;databas

  • Remove column in datatable 2010-03-11

    I am exporting a datatable to an excel sheet successfully... In that excel sheet i have to display the columns(customerid,Productname,referenceno) of the data table except the last column.... now how can i display the data table in excel without disp

  • SqlBulkCopy WriteToServer method not writing any data when using datatable 2010-11-23

    All of the following processing takes place on the localmachine: I have a source database (on the server) and a destination database (local machine). I have a list of tables that I wish to copy from the source to the destination, ie server-->local

Copyright (C), All Rights Reserved.

processed in 0.164 (s). 11 q(s)