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 6681911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:38:38+00:00 2026-05-26T04:38:38+00:00

AFAIK you can load one DataSet from another DataSet via IDataReader i.e. new DataSet().Load(existingDataSet.CreateDataReader());

  • 0

AFAIK you can load one DataSet from another DataSet via IDataReader i.e.

new DataSet().Load(existingDataSet.CreateDataReader());
// should now have two DataSets with the same contents

I haven’t been able to find any documentation that suggests this is not possible. So, can anyone explain, why the following NUnit test fails?

[Test]
public void Should_be_able_to_load_one_dataset_from_another()
{
    var tableA = new DataTable("A");
    //tableA.Columns.Add("ColumnA", typeof(int));

    var tableB = new DataTable("B");
    tableB.Columns.Add("ColumnB", typeof(int));

    var tableC = new DataTable("C");

    using (var original = new DataSet())
    {
        original.Tables.Add(tableA);
        original.Tables.Add(tableB);
        original.Tables.Add(tableC);

        using (var expectedReader = original.CreateDataReader())
        using (var actual = new DataSet())
        {
            actual.Load(expectedReader, LoadOption.OverwriteChanges, "A", "B", "C");

            Assert.That(actual.HasErrors, Is.False);

            for (var i = 0; i < original.Tables.Count; i++)
                Assert.That(actual.Tables[i].Columns.Count, Is.EqualTo(original.Tables[i].Columns.Count), 
                    "Table {0} had the wrong number of columns.", i); // fails here
        }
    }
}

The test passes if you uncomment ColumnA. So it would seem there is possibly a bug in DataSet.Load() that, after encountering a table with no columns, the next table will be imported with no columns either. Note the empty table is not affected, only the table immediately following it, so if it is only the last table that is empty the test will pass.

Have I found a bug in the BCL? Or is there an explanation for this behaviour?

  • 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-26T04:38:39+00:00Added an answer on May 26, 2026 at 4:38 am

    Before I looked into the code, I was skeptical that this could be a bug, but now I believe it is.

    Looking at the DataSet.Load method in Reflector, it goes through the table names provided and creates the tables if they do not exist. So in this case, it creates tables “A”, “B”, and “C”.

    Then it loads the data, calling through the following methods and passing the target tables in the destination data set as a DataTable[]:

    • DataSet.Load(IDataReader, LoadOption, FillErrorEventHandler, params DataTable[])
    • LoadAdapter.FillFromReader(DataTable[], IDataReader, int, int)
    • LoadAdapter.Fill(DataTable[], IDataReader, int, int)

    In this last Fill method, it loops through the DataTable[] to fill each table, but it only fills the table if it has fields:

    if (container.FieldCount > 0)
    {
        if ((0 < i) && !this.FillNextResult(container))
        {
            goto Label_00DE;
        }
        int num4 = this.FillFromReader(null, dataTables[i], null, container, startRecord, maxRecords, null, null);
        if (i == 0)
        {
            num2 = num4;
        }
    }
    

    Note that when it fills the table, it also calls NextResult on the reader (in FillNextResult), but there is no else to call NextResult if the FieldCount is 0, and that throws everything afterwards out of synch.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

AFAIK, extern keyword should be used for declaration and no value can be associated
I have a strange problem. Afaik I can inject a SessionScoped bean into a
AFAIK, all types are derived from System.Object class. Considering this, how can I calculate
Can anyone tell why this doesn't work? http://www.webdevout.net/test?01x afaik it should; my <div> elements
One can design plugins in C using 2 techniques (AFAIK): Use dlopen() all the
AFAIK one of the objectives of Stack Overflow is to make sure anyone can
I'm trying to save email attachment from Google mail account. AFAIK, it can be
AFAIK when reducing an array we can only output once variable at the end
Afaik, you can change/manipulate browser settings in Mozilla/Netscape browsers. For Instance netscape.security.PrivilegeManager.enablePrivilege('someprivilege'); Of course
AFAIK with XmlHttpRequest I can download and upload data just with the send method.

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.