none
LINQ: use "GroupBy" can not return "dataview" RRS feed

  • Question

  •  

     

     

    Dim query = datatable.AsEnumerable().Where(Function(r) r("Field1").ToString() <> String.Empty)
    Datagridview1.DataSource = query.AsDataView
    

     

    Why when I use "GroupBy" can not return "dataview"

    Dim query = datatable.AsEnumerable().GroupBy(Function(r) r("Field1"))
    Datagridview1.DataSource = query.AsDataView 'return Array
    Best regards,



    • Edited by tommyVB Tuesday, July 12, 2011 9:18 AM
    • Moved by Kee Poppy Wednesday, July 13, 2011 7:33 AM (From:Visual Basic Express Edition)
    Tuesday, July 12, 2011 2:19 AM

Answers

  • Because a DataView is a special class which is connected to a datatable.

    Linq return normally as it is a collection a anonymous class, although you can set that to a new List or an Array, but not to a DataView.

     


    Success
    Cor
    Tuesday, July 12, 2011 7:34 AM
  • Thank you for posting.

    Like Cor Ligthert's said, query was a IEnumerable<T> type returning. For VB, you should use For Each to iterate this enum list in your project.

    Best Regards,


    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, July 13, 2011 8:30 AM

All replies

  • Because a DataView is a special class which is connected to a datatable.

    Linq return normally as it is a collection a anonymous class, although you can set that to a new List or an Array, but not to a DataView.

     


    Success
    Cor
    Tuesday, July 12, 2011 7:34 AM
  • Thank you for posting.

    Like Cor Ligthert's said, query was a IEnumerable<T> type returning. For VB, you should use For Each to iterate this enum list in your project.

    Best Regards,


    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, July 13, 2011 8:30 AM