473,396 Members | 2,147 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,396 software developers and data experts.

Dataset Naming Question

I have the following code that creates a couple of XML files:

Dim dt1 As New DataTable("P1JoyUp")

If H = True Then

Dim dsH As New DataSet("HCPViewer")

dsH.Tables.Add(dt1)

dt1.Columns.Add("Top")

Dim dr1 As DataRow = dsH.Tables("P1JoyUp").NewRow

dr1("Top") = lblP1JoyUp.Top.ToString

dsH.Tables("P1JoyUp").Rows.Add(dr1)

dsH.WriteXml(SaveFileDialog1.FileName)

End If

If V = True Then

Dim dsV As New DataSet("VCPViewer")

dsV.Tables.Add(dt1)

dt1.Columns.Add("Top")

Dim dr1 As DataRow = dsV.Tables("P1JoyUp").NewRow

dr1("Top") = lblP1JoyUp.Top.ToString

dsV.Tables("P1JoyUp").Rows.Add(dr1)

dsV.WriteXml(SaveFileDialog1.FileName)

End If

If R = True Then

Dim dsrH As New DataSet("HCPViewer")

dsrH.Tables.Add(dt1)

dt1.Columns.Add("Top")

Dim dr1 As DataRow = dsrH.Tables("P1JoyUp").NewRow

dr1("Top") = lblP1JoyUp.Top.ToString

dsrH.Tables("P1JoyUp").Rows.Add(dr1)

dsrH.WriteXml(SaveFileDialog1.FileName)

Dim dsrV As New DataSet("VCPViewer")

dsrV.Tables.Add(dt1)

dt1.Columns.Add("Top")

Dim dr1 As DataRow = dsrV.Tables("P1JoyUp").NewRow

dr1("Top") = lblP1JoyUp.Top.ToString

dsrV.Tables("P1JoyUp").Rows.Add(dr1)

dsrV.WriteXml(SaveFileDialog1.FileName)

End If
If condition "H" is true I create a dataset HCPViewer and add a table dt1.
This works great.
If condition "V" is true i create a dataset VCPViewer and add a table dt1.
This also works great
If condition "R" is true I can run throught the "H" logic but when I get to
the "V" logic it errors out on the "dsrV.Tables.Add(dt1) line with the
following error:

An unhandled exception of type 'System.ArgumentException' occurred in
system.data.dll

Additional information: DataTable already belongs to another DataSet.

Is it true that I can't have the same table name in two different datasets
They are being written to completely different files. If I can't do this,
and it seems I can't, what are my options here?

Thank you,
John


Nov 20 '05 #1
3 1908
A datatable can belong to only one dataset.

Your can remove the datatable from the first dataset, add it to the second.
Do your processing, then remove it again and place it back in the original
dataset.

"jcrouse" <me> wrote in message
news:u7**************@TK2MSFTNGP12.phx.gbl...
I have the following code that creates a couple of XML files:

Dim dt1 As New DataTable("P1JoyUp")

If H = True Then

Dim dsH As New DataSet("HCPViewer")

dsH.Tables.Add(dt1)

dt1.Columns.Add("Top")

Dim dr1 As DataRow = dsH.Tables("P1JoyUp").NewRow

dr1("Top") = lblP1JoyUp.Top.ToString

dsH.Tables("P1JoyUp").Rows.Add(dr1)

dsH.WriteXml(SaveFileDialog1.FileName)

End If

If V = True Then

Dim dsV As New DataSet("VCPViewer")

dsV.Tables.Add(dt1)

dt1.Columns.Add("Top")

Dim dr1 As DataRow = dsV.Tables("P1JoyUp").NewRow

dr1("Top") = lblP1JoyUp.Top.ToString

dsV.Tables("P1JoyUp").Rows.Add(dr1)

dsV.WriteXml(SaveFileDialog1.FileName)

End If

If R = True Then

Dim dsrH As New DataSet("HCPViewer")

dsrH.Tables.Add(dt1)

dt1.Columns.Add("Top")

Dim dr1 As DataRow = dsrH.Tables("P1JoyUp").NewRow

dr1("Top") = lblP1JoyUp.Top.ToString

dsrH.Tables("P1JoyUp").Rows.Add(dr1)

dsrH.WriteXml(SaveFileDialog1.FileName)

Dim dsrV As New DataSet("VCPViewer")

dsrV.Tables.Add(dt1)

dt1.Columns.Add("Top")

Dim dr1 As DataRow = dsrV.Tables("P1JoyUp").NewRow

dr1("Top") = lblP1JoyUp.Top.ToString

dsrV.Tables("P1JoyUp").Rows.Add(dr1)

dsrV.WriteXml(SaveFileDialog1.FileName)

End If
If condition "H" is true I create a dataset HCPViewer and add a table dt1.
This works great.
If condition "V" is true i create a dataset VCPViewer and add a table dt1.
This also works great
If condition "R" is true I can run throught the "H" logic but when I get to the "V" logic it errors out on the "dsrV.Tables.Add(dt1) line with the
following error:

An unhandled exception of type 'System.ArgumentException' occurred in
system.data.dll

Additional information: DataTable already belongs to another DataSet.

Is it true that I can't have the same table name in two different datasets
They are being written to completely different files. If I can't do this,
and it seems I can't, what are my options here?

Thank you,
John

Nov 20 '05 #2
Hi John,

I think you are looking for dataset.clone or/and dataset.copy here.

Have a look on MSDN for that.

Cor
Nov 20 '05 #3
Resolved!

Thanks,
John

"jcrouse" <me> wrote in message
news:u7**************@TK2MSFTNGP12.phx.gbl...
I have the following code that creates a couple of XML files:

Dim dt1 As New DataTable("P1JoyUp")

If H = True Then

Dim dsH As New DataSet("HCPViewer")

dsH.Tables.Add(dt1)

dt1.Columns.Add("Top")

Dim dr1 As DataRow = dsH.Tables("P1JoyUp").NewRow

dr1("Top") = lblP1JoyUp.Top.ToString

dsH.Tables("P1JoyUp").Rows.Add(dr1)

dsH.WriteXml(SaveFileDialog1.FileName)

End If

If V = True Then

Dim dsV As New DataSet("VCPViewer")

dsV.Tables.Add(dt1)

dt1.Columns.Add("Top")

Dim dr1 As DataRow = dsV.Tables("P1JoyUp").NewRow

dr1("Top") = lblP1JoyUp.Top.ToString

dsV.Tables("P1JoyUp").Rows.Add(dr1)

dsV.WriteXml(SaveFileDialog1.FileName)

End If

If R = True Then

Dim dsrH As New DataSet("HCPViewer")

dsrH.Tables.Add(dt1)

dt1.Columns.Add("Top")

Dim dr1 As DataRow = dsrH.Tables("P1JoyUp").NewRow

dr1("Top") = lblP1JoyUp.Top.ToString

dsrH.Tables("P1JoyUp").Rows.Add(dr1)

dsrH.WriteXml(SaveFileDialog1.FileName)

Dim dsrV As New DataSet("VCPViewer")

dsrV.Tables.Add(dt1)

dt1.Columns.Add("Top")

Dim dr1 As DataRow = dsrV.Tables("P1JoyUp").NewRow

dr1("Top") = lblP1JoyUp.Top.ToString

dsrV.Tables("P1JoyUp").Rows.Add(dr1)

dsrV.WriteXml(SaveFileDialog1.FileName)

End If
If condition "H" is true I create a dataset HCPViewer and add a table dt1.
This works great.
If condition "V" is true i create a dataset VCPViewer and add a table dt1.
This also works great
If condition "R" is true I can run throught the "H" logic but when I get to the "V" logic it errors out on the "dsrV.Tables.Add(dt1) line with the
following error:

An unhandled exception of type 'System.ArgumentException' occurred in
system.data.dll

Additional information: DataTable already belongs to another DataSet.

Is it true that I can't have the same table name in two different datasets
They are being written to completely different files. If I can't do this,
and it seems I can't, what are my options here?

Thank you,
John

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: VK | last post by:
09/30/03 Phil Powell posted his "Radio buttons do not appear checked" question. This question led to a long discussion about the naming rules applying to variables, objects, methods and properties...
3
by: C# Learner | last post by:
Why can't people abide by naming conventions?! It seems that most people have to have their /own/ custom convention.
4
by: Mark Broadbent | last post by:
stupid question time again to most of you experts but this is something that continually bothers me. I am trying to get into the habit of naming variables and controls in an assembly as per...
14
by: 42 | last post by:
Hi, Stupid question: I keep bumping into the desire to create classes and properties with the same name and the current favored naming conventions aren't automatically differentiating them......
3
by: Michelle Stone | last post by:
Thanks for your message I tried again and again... but didn't work. Can u please detail the exact steps to perform? This is what I do. In field explorer, i right-click the dataset to update....
114
by: Jonathan Wood | last post by:
I was just wondering what naming convention most of you use for class variables. Underscore, "m_" prefix, camel case, capitalized, etc? Has one style emerged as the most popular? Thanks for...
5
by: John | last post by:
Hi, I am developing a windows app using C# 2005. This app uses SQL Server or Oracle database depending on the what the user is using. Can I create one typed dataset and use it for SQL Server and...
35
by: Smithers | last post by:
Is it common practise to begin the name of form classes with "frm" (e.g., frmOneForm, frmAnotherForm). Or is that generally considered an outdated convention? If not "frm" what is a common or...
12
by: Andy B | last post by:
I need to custom build and use a dataset in c# to use with xml. Does anybody know where I can find out how to do something like this? I was going to create a class that generated the dataset and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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,...

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.