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")
                arrPrevTensionLoad.Add(row("loadValue"))

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

                dbTEST_DETAILS_Load.Rows.Add(newRow)
                x += 1
            Next

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

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

            dsDetails.Tables.Add(dt(cnt))

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.
BlakeMcKennaAsked:
Who is Participating?
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.
0
BlakeMcKennaAuthor Commented:
I've requested that this question be deleted for the following reason:

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

Your question, your audience. Choose who sees your identity—and your question—with question security.

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.
0

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
mlmccCommented:
Jacques, I intended my comment to get the asker to provide his answer.  Poor choice of words on my part.

mlmcc
0
BlakeMcKennaAuthor Commented:
I actually ended up eliminating the dynamic table. We had a change in requirements. Sorry for missing the question.
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.