473,418 Members | 2,121 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

Error Message - Adding Table to Dataset

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
6 2208
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Saso Zagoranski | last post by:
Hi! I have a little search textbox, which goes through a dataset as the user types in the textbox... If the user types "1", then all the fields beginning with a 1 get shown in the datagrid... ...
4
by: Troy | last post by:
We recently installed the .Net framework on a windows 2000 server. Shortly after that we experienced intermitant problems running a web based program that accesses an Access 2002 database. The...
11
by: Steve Hoyer | last post by:
I am trying to deploy my first asp.net app to our webserver (2K server, IIS 5) My start page comes up and you can get to the subsequent pages that are tied into our sql server (2K). Each page...
0
by: Susil Patro | last post by:
Hi all, I have installed Visual Studio dot net version 2003, in my machine. I opened a new project for developing an application related to crystal reports. I got the following error, while I...
1
by: Mikey G | last post by:
Hi, I created a simple VB.NET 2003 application through Visual Studio that connects to a MySQL database and loads a table into a Dataset, and then displays that table information in a DataGrid on a...
6
by: Rudy | last post by:
Hi all, I know this is easy, just can't seem to get it. I have a windows form, and a text box, with a value already in it. I need to add that value to a table. It's just one value, so the entire...
6
by: Dacuna | last post by:
I have a dataset that I created programmatically and bind to a datagrid. When I add a row and I .show the form I get an error "Error creating window handle" This only happens if I have the code...
13
by: dbuchanan | last post by:
Hello, Here is the error message; ---------------------------- Exception Message: ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child key values (5) to exist in the...
17
by: =?Utf-8?B?SGVyYg==?= | last post by:
I have created a report and subreport in VB/ASP.NET. The report works fine but the subreport will not display. The subreport, when displayed as a standalone report, works fine. Any help I can...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.