Adding an array of DataTables to a DataSet?

I'm trying to dynamically add DataTables to a DataSet and I keep getting the error message of:

"DataTable already belongs to this DataSet".

Here is what my code looks like...

            Dim x As Integer = 1
            Dim cnt As Integer = 0
            Dim dt() As DataTable

            For Each row As DataRow In dbTempTensionTest.Rows
                newRow = dbTEST_DETAILS_Load.NewRow

                newRow("testNO") = uc.testNO
                newRow("loadLink_ID") = x
                newRow("loadingPoint") = row("loadingPoint")
                newRow("loadValue") = row("loadValue")

                newRow("output") = row("output")
                newRow("nonLinearity") = row("nonLinearity")
                newRow("hysteresis") = row("hysteresis")
                newRow("forceError") = row("forceError")

                x += 1

            cnt = uc.testNO - 1                
            ReDim Preserve dt(cnt)

            dt(cnt) = dbTEST_DETAILS_Load
            dt(cnt).TableName = "table" & uc.testNO


Open in new window

The "cnt" variable is just a counter but is initialized to 0 for the dt() index. The code above executes up to 12 times, hence the need for an indexed DataTable. I'm not sure what I'm doing wrong except that the "dt" itself is just defined there and doesn't have any columns. I don't think that's the problem but not certain on that.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jacques Bourgeois (James Burger)PresidentCommented:
The value of uc.testNO probably does not change, thus the name built by "table" & uc.testNO is always the same, and you cannot have 2 tables with the same name in the same DataSet.
BlakeMcKennaAuthor Commented:
I've requested that this question be deleted for the following reason:

I figured it out on my own.
Jacques Bourgeois (James Burger)PresidentCommented:
You should remove the question sooner in such a case. We spend time, free time, answering your questions.
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Jacques Bourgeois (James Burger)PresidentCommented:
The proper answer was given to an opened question. If the user had found the problem on its own, he should have deleted the question.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jacques, I intended my comment to get the asker to provide his answer.  Poor choice of words on my part.

BlakeMcKennaAuthor Commented:
I actually ended up eliminating the dynamic table. We had a change in requirements. Sorry for missing the question.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.