Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7535235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:15:34+00:00 2026-05-30T06:15:34+00:00

I have a dataset (called dataSet below) with a single table and some records

  • 0

I have a dataset (called dataSet below) with a single table and some records in it. One of the columns is called Message and contains an error message. If any records have a value in this field I want to copy it into an error dataset (errorDataSet below) and then remove it from the original dataset. I managed to get this far with LINQ:

        DataSet errorDataSet = dataSet.Copy();

        //find all records that have a Message column value
        var query = from row in errorDataSet.Tables[0].AsEnumerable()
                    where !String.IsNullOrEmpty(row.Field<string>("Message"))
                    select row;

        DataSet tempErrorDataSet = errorDataSet.Clone();
        foreach (var row in query)
        {
            tempErrorDataSet.Tables[0].Clear();
            tempErrorDataSet.Tables[0].ImportRow(row);
            utility.WriteError(connectorName, row["Message"].ToString(), tempErrorDataSet);

            //remove the error row from the good data
            dataSet.Tables[0].Rows.Remove(row);
        }

The bottom line throws an exception or I get errors regarding modifying a collection etc. I’m sure there is a simple way of doing this in LINQ.

Note: The reason I have tempErrorDataSet is that I convert it to XML and pass it into a stored proc – it only takes a record at a time in that format, hence I clear it each time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:15:35+00:00Added an answer on May 30, 2026 at 6:15 am

    Your query is enumerating (indirectly) through the rows in the table. As you should already know, you cannot modify a collection (remove something in this case) as you enumerate over it. Throw the contents into a list beforehand. That way you’re not enumerating through the actual table but a copy of some rows.

    var query = (from row in errorDataSet.Tables[0].AsEnumerable()
                 where !String.IsNullOrEmpty(row.Field<string>("Message"))
                 select row).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataSet that contains a few columns. One of these columns is
I'm using a dataset. I have a table Adapter called PackageTableAdapter , which contains
I have a DataSet called Apples. I need to massage the data table in
I have a table called Shoppings in my SQL db. This one has a
Hi I have a DataSet and it has a table called Header. The Header
Greetings, I'm working in windows application using C#. I have typed-dataset called packetsDBDataSet and
I have DataSet which has 3 columns. Name - insurance comp. name - treatmentDate
I have a DataSet with a DataTable that correctly fills a single DataRow through
I have a DataSet with a DataTable having the columns Number and Description. I
I have a very large dataset (100,000) to be display, but any browser I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.