?
Solved

Need proper syntax for parallel.foreach table in a dataset

Posted on 2014-08-24
2
Medium Priority
?
1,746 Views
Last Modified: 2014-08-24
Could use some quick assistance on running parallelforeach on a dataset .
Here is my code:

Parallel.ForEach<DataTable>(dataSet.Tables, table =>
            {
                if (table.Rows.Count > 0)
                {
                            //do some stuff
                  }                    
            });
//also tried
Parallel.ForEach( dataSet.Tables, table =>
            {
                if (table.Rows.Count > 0)
                {
                            //do some stuff
                  }                    
            });

Open in new window



Thx
0
Comment
Question by:Focker513
2 Comments
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 40282329
Hi Focker513;

The issue I think you are having is that dataSet.Tables holds a collection of tables and you need to give it a single table by using it index, use the [index into collection] or you can use its name if you have given it a name like so ["TheTableName"]. See the code snippet, it is using the very first table in the collection, index 0.

Parallel.ForEach<DataTable>(dataSet.Tables[0], table =>
            {
                if (table.Rows.Count > 0)
                {
                            //do some stuff
                  }                    
            });

Open in new window

0
 

Author Comment

by:Focker513
ID: 40282349
Cool, here is the working code:
    
       Parallel.For(0, dataSet.Tables.Count, i =>
        {
            if (dataSet.Tables[i].Rows.Count > 0) 
            {
               //Do some stuff
            }
        }

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question