locked
OrderBy on datatable in C# RRS feed

  • Question

  • Hi,

    I have a communication table, and I want to fetch all the communication of type 'Business' and want to have the last modified contact from them. like if I have all the records in datatable, then I want something like :

    dtCommunication.Select("Type='Business'").OrderBy("LastModifiedDate");

    I know I am missing on the syntax, Can anyone correct the same??

    Thanks


    Thanks!! http://dotnetcity.wordpress.com
    Monday, February 14, 2011 9:51 AM

Answers

  • You can just use 
    dtCommunication.Select("Type='Business'", "LastModifiedDate DESC");
    
    Here is the corresponding documentation: DataTable.Select Method
    MCTS, CodeProject MVP 2008
    • Proposed as answer by Paul Zhou Wednesday, February 16, 2011 9:23 AM
    • Marked as answer by Paul Zhou Tuesday, February 22, 2011 2:15 AM
    Monday, February 14, 2011 10:43 AM

All replies

  • getting below error:

    Error 60 The type arguments for method 'System.Linq.Enumerable.OrderBy<TSource,TKey>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,TKey>, System.Collections.Generic.IComparer<TKey>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.


    Thanks!! http://dotnetcity.wordpress.com
    Monday, February 14, 2011 10:36 AM
  • You can just use 
    dtCommunication.Select("Type='Business'", "LastModifiedDate DESC");
    
    Here is the corresponding documentation: DataTable.Select Method
    MCTS, CodeProject MVP 2008
    • Proposed as answer by Paul Zhou Wednesday, February 16, 2011 9:23 AM
    • Marked as answer by Paul Zhou Tuesday, February 22, 2011 2:15 AM
    Monday, February 14, 2011 10:43 AM
  • Hi GuruGuns,

       Please refer below links for detail information:

       DataTable.Select Method 
       DataTable.Select Method (String, String)

      


    Thanks,

    Paras Sanghani

    http://parassanghani.blogspot.com/

    Mark As Answer if it helped you.

    • Edited by Paras Sanghani Monday, February 14, 2011 11:03 AM Formatting
    Monday, February 14, 2011 11:03 AM