locked
LINQ statement gives identifier expected

    Question

  • I am a newbee to vb.net 2010 and am converting vb6 files.    I am trying to total values in a column of a table using linq.   I have read that

    Dim TempTotal = Aggregate row As DataRow In ExpTab.AsEnumerable() Into (Sum(row.Field(Of Double)("Dol")))

    will total the values of the column Dol.    
    This gives me "identifier expected " error.   I have added system linq to my references and system.core.

    What am I missing?

    Is LINQ something I should learn if I use vb.net?   I think I can use sum in an sql statement as I used to do in VB6, but it appears that LINQ will have value and save some steps.

    Wednesday, May 16, 2012 1:53 PM

Answers

  • Well, LINQ is an option, not a requirement (though it can be a really good option sometimes).

    In this case I would just use the Compute() method on the data table if all of the relevant rows are already loaded:

    Dim TempTotal As Integer = CInt(ExpTab.Compute("SUM(Dol)", String.Empty))

    The difference between using LINQ/Compute() and using a special SELECT query is where the routine executes... if you use LINQ/Compute then the rows all need to be loaded into the client dataset and then calcuated.  If you use a SELECT query with the SUM command then all of the calculations are done on the server and only the result is returned to the client.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by jjobcorp Wednesday, May 16, 2012 5:56 PM
    Wednesday, May 16, 2012 3:51 PM
    Moderator

All replies

  • Well, LINQ is an option, not a requirement (though it can be a really good option sometimes).

    In this case I would just use the Compute() method on the data table if all of the relevant rows are already loaded:

    Dim TempTotal As Integer = CInt(ExpTab.Compute("SUM(Dol)", String.Empty))

    The difference between using LINQ/Compute() and using a special SELECT query is where the routine executes... if you use LINQ/Compute then the rows all need to be loaded into the client dataset and then calcuated.  If you use a SELECT query with the SUM command then all of the calculations are done on the server and only the result is returned to the client.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by jjobcorp Wednesday, May 16, 2012 5:56 PM
    Wednesday, May 16, 2012 3:51 PM
    Moderator
  • thanks.   The "identifier expected" error threw me as I thought this would be an opportunity to learn LINQ.   Looks like it wasn't a good opportunity and I will wait until the next one.
    Wednesday, May 16, 2012 5:57 PM