Răspuns how dataset use in Parallel.ForEach

  • 8 martie 2012 08:43
     
     
     

    Following code showing some errors

    Parallel.ForEach<DataRow>(oDsData.Tables[0].Rows, dr =>
                    {
                        // code in here
                    });

    i need syntax for using dataset in parallel foreach


    shijo


Toate mesajele

  • 8 martie 2012 08:56
     
     Răspuns Are cod

    DataTable.Rows returns a DataRowCollection which only implements IEnumerable, not IEnumerable<DataRow>. Use the AsEnumerable() extension method on DataTable (from DataTableExtensions) instead:

        Parallel.ForEach(dt.AsEnumerable(), drow =>
    {
        ...
    code in here
        ...
    });

    shijo


  • 8 martie 2012 08:57
     
     
    there any way without using AsEnumerable() .

    shijo

  • 8 martie 2012 10:23
     
     Răspuns Are cod

    Yes. It is possible. See the below code,

    Parallel.ForEach<DataRow>(oDsData.Tables[0].Rows.OfType<DataRow>(), dr =>
    {
         // code in here
    });

    Other than this there is no option than to use AsEnumerable. I hope this helps.

    Please mark this post as answer if it solved your problem. Happy Programming!

  • 13 martie 2012 13:39
     
     

    there is any performance degradation using dataset to linq(oDsData.Tables[0].Rows.OfType<DataRow>()


    shijo