By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,659 Members | 910 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,659 IT Pros & Developers. It's quick & easy.

Error Message - Adding Table to Dataset

P: n/a
I'm trying to add a table to a dataset but get the error:

"A DataTable named 'BordDates0040' already belongs to this DataSet."

Code:
Dim dtBordDates As DataTable
dtBordDates = LoadTable(strDBPath & strDBName, strTableName,
strSQL)

Dim ds2 As DataSet = New DataSet()
Dim dt2 As DataTable = New DataTable()
dt2 = dtBordDates.Copy()
ds2.Tables.Add(dt2) '**** Error happens here ****

Any Suggestions?

Thanks, Mark
Nov 23 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Mark,
Any Suggestions?

Yes rename it before you add it. There is a datatable.tablename

http://msdn.microsoft.com/library/de...eNameTopic.asp

I hope this helps,

Cor
Nov 23 '05 #2

P: n/a
Cor -

This worked, thanks.

Its interesting, I had to change the TableName property of thefirst table:
dtBordDates

eg.
Dim dtBordDates As DataTable
dtBordDates = LoadTable(strDBPath & strDBName, strTableName,
strSQL)

dtBordDates.TableName = "BordDates" '***** New Code works *****

Dim ds2 As DataSet = New DataSet()
Dim dt2 As DataTable = New DataTable()
dt2 = dtBordDates.Copy()
ds2.Tables.Add(dt2)

I had tried unsuccessfully to change the TableName of the new DataTable:
dt2.TableName = "BordDates" '***** Did not work *****

Thanks, Again
Mark

"Cor Ligthert [MVP]" wrote:
Mark,
Any Suggestions?

Yes rename it before you add it. There is a datatable.tablename

http://msdn.microsoft.com/library/de...eNameTopic.asp

I hope this helps,

Cor

Nov 23 '05 #3

P: n/a
Cor -

I've played around and was able to get it too work with the following code:

Dim dtBordDates As DataTable
dtBordDates = LoadTable(strDBPath & strDBName, strTableName, strSQL)

Dim ds2 As DataSet = New DataSet()

ds2.Tables.Add(dtBordDates.Copy()) '**** New Code ****

So, I'm able to add a table to the dataset directly without renaming it.
Less code is better.

Any issues come to mind? Seem OK to you?

Thanks, Mark



"Cor Ligthert [MVP]" wrote:
Mark,
Any Suggestions?

Yes rename it before you add it. There is a datatable.tablename

http://msdn.microsoft.com/library/de...eNameTopic.asp

I hope this helps,

Cor

Nov 23 '05 #4

P: n/a
Mark,
Just trying to understand...

Is it your intent to have multiple copies of the same table in your dataset?

I'm not sure, but it sounds like you are adding the same table more than
once, but unintentionally. If the table exists and is not supposed to, then
it is probably because you are calling the code more than once.
"Mark" <Ma**@discussions.microsoft.com> wrote in message
news:C2**********************************@microsof t.com...
Cor -

I've played around and was able to get it too work with the following code:
Dim dtBordDates As DataTable
dtBordDates = LoadTable(strDBPath & strDBName, strTableName, strSQL)

Dim ds2 As DataSet = New DataSet()

ds2.Tables.Add(dtBordDates.Copy()) '**** New Code ****

So, I'm able to add a table to the dataset directly without renaming it.
Less code is better.

Any issues come to mind? Seem OK to you?

Thanks, Mark



"Cor Ligthert [MVP]" wrote:
Mark,
>Any Suggestions?

Yes rename it before you add it. There is a datatable.tablename

http://msdn.microsoft.com/library/de...eNameTopic.asp
I hope this helps,

Cor

Nov 23 '05 #5

P: n/a
Mark,

Sorry I did more look at what you wrote than to the problem (That is as soon
as I see methods as "loadDataTable" I stop reading because than I can not
see what is behind that. (I could have guessed that simple one, however I
did not).

You can even do
\\\
dim ds2 as New dataset
ds2.tables.add(dtBordDates.Copy)
///
Have a look as well to that assignment of the datatable, often samples are
translated C# samples and therefore the longer needed C# code is used.

Sorry that I did not see it direct.

I hope this helps anyhow

Cor
Nov 23 '05 #6

P: n/a
Jim -

My intention is to have several unique tables in the Dataset (I would think
this is the usual practice).

I really don't get why ADO.NET was returning the error message ("A DataTable
named 'BordDates0040' already belongs to this DataSet.") as the Dataset being
populated was empty.

I apparently had some syntax incorrect (who knows what).

The final code I arrived at was the very concise and direct:

Dim ds2 As New DataSet
ds2.Tables.Add(LoadTable(strDBPath & strDBName, strTableName, strSQL).Copy)

It excludes the "dt2" datatable object altogether. Sometimes (alot of
times) it takes alittle adversity to see the light.

Thanks Mark

"Jim Underwood" wrote:
Mark,
Just trying to understand...

Is it your intent to have multiple copies of the same table in your dataset?

I'm not sure, but it sounds like you are adding the same table more than
once, but unintentionally. If the table exists and is not supposed to, then
it is probably because you are calling the code more than once.
"Mark" <Ma**@discussions.microsoft.com> wrote in message
news:C2**********************************@microsof t.com...
Cor -

I've played around and was able to get it too work with the following

code:

Dim dtBordDates As DataTable
dtBordDates = LoadTable(strDBPath & strDBName, strTableName, strSQL)

Dim ds2 As DataSet = New DataSet()

ds2.Tables.Add(dtBordDates.Copy()) '**** New Code ****

So, I'm able to add a table to the dataset directly without renaming it.
Less code is better.

Any issues come to mind? Seem OK to you?

Thanks, Mark



"Cor Ligthert [MVP]" wrote:
Mark,

>>Any Suggestions?
Yes rename it before you add it. There is a datatable.tablename

http://msdn.microsoft.com/library/de...eNameTopic.asp
I hope this helps,

Cor


Nov 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.