473,573 Members | 3,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataSet from Method returns error

5 New Member
Exception Details: System.Argument Exception: DataTable already belongs to another DataSet.
Googling for this error shows several post of people trying to manipulate a table within a dataset. Others suggest using .clone() and .copy(). Neither results in a different error.

Within another class, I've gathered two tables of data for a nested repeater. To return a table, int, string or anything else in C#, one sets their local variable equal to the returned data of the method. Doing this with a DataSet provides the above error.

Q: How do I pull a DataSet returned from a method equal to a local DataSet variable?

It is a web site, though I believe this to be a C# syntax issue. Let me know if I'm wrong.

OS: Windows XP SP3
MS VS 05 v8.0.50727.42
.NET 2.0.50727

Expand|Select|Wrap|Line Numbers
  1. //Within main class
  2. int[] iaInvID = {2,5,8,11};
  3. DataSet ds = new DataSet();
  4. ds = MyDll.MyDllsClass.ReturnSalesSummary(iaInvID);
Expand|Select|Wrap|Line Numbers
  1. //Within MyDll.MyDllsClass class
  2. public static DataSet ReturnSalesSummary(int[] iaInvID)
  3. {
  4.     DataSet ds = new DataSet();
  6.     ds = CreateRelationshipTable(ds, iaInvID);
  7.     ds.Tables.Add(ReturnSalesSummary_DummySet(iaInvID));
  9.     ds.Relations.Add("InvID",
  10.     ds.Tables[0].Columns["InvID"],
  11.     ds.Tables[1].Columns["InvID"]);
  13.     return ds;
  14. }
  16. private static DataSet CreateRelationshipTable(DataSet ds, int[] iaInvID)
  17. {
  18.     //For each id, create a row of that id.  This allows a one to many relationship
  19.     //with the table from the db.
  20.     DataTable dt = ds.Tables.Add("InvIDs");
  21.     dt.Columns.Add("ID", typeof(int));
  22.     foreach (int i in iaInvID)
  23.     dt.Rows.Add(i);
  24.     return ds;
  25. }
  27. private static DataTable ReturnSalesSummary_DummySet(int[] iaInvID)
  28. {
  29.     //Until the SQL statement is correct, create a dummy table of similar data.
  30.     DataSet ds = new DataSet();
  31.     DataTable dt = ds.Tables.Add();
  33.     dt.Columns.Add("RowID", typeof(int));
  34.     dt.Columns.Add("InvID", typeof(int));
  35.     dt.Columns.Add("StationID", typeof(string));
  37.     int iCount = 0;
  38.     string[] saStationID = { "Workstation 1", "Workstation 2", "Online Sales" };
  40.     foreach (int i in iaInvID)
  41.     for( int i2 = 0; i2 < 3; i2++)
  42.     {
  43.         dt.Rows.Add(iCount, i, saStationID[i2]);
  44.         iCount++;
  45.     }
  47.     return ds.Tables[0];
  48. }
Apr 6 '09 #1
3 2145
7,872 Recognized Expert Expert
I think you need to use the .Copy() method to make a copy of the DataTable object if you want to insert it into another dataset. (Just like you would with DataRows)
Apr 6 '09 #2
5 New Member
Expand|Select|Wrap|Line Numbers
  1. //Within main class
  2. ds = Pyramedium_Enterprise_Reporting.Report_TenderSummaries.ReturnSalesSummary(iaInvID).Copy();
As before, this results in the same error. Am I using .Copy() wrong?
Apr 6 '09 #3
5 New Member
[Edit limit expired]
The error pointed out the method at line 4 of the first set of code, making me assume that was the line causing the issue. Using .Copy() in line 7 of the second set of code pushes me to a new error message.
Expand|Select|Wrap|Line Numbers
  1. ds.Tables.Add(ReturnSalesSummary_DummySet(iaInvID).Copy());
Thanks Plater.
Apr 6 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Programatix | last post by:
Hi, I'm working on a project which includes WebServices and Windows Form application. The Windows Form application will call the WebServices to retrieve data from database. The data will be returned as DataSet. Now, here's the problem. On .NET Framework 1.1, if any rows in the dataset returned contain errors (marked by calling the...
by: John Holmes | last post by:
I have a web interface where the user types in ID's one at a time. After an ID is typed in, a button is clicked and the button click event has code that does a query and returns a data reader and then appends the data to a dataset that is built in the Page_Load code in the if(!isPostBack) block. When I try to add a row in the button click...
by: William Gower | last post by:
I have a method called RetrieveAll that returns a Dataset The object that is calling this method expects to receive a UserDS. I don't want the RetrieveAll to have to know about the UserDS but just return a dataset and the calling method will convert it to a specific typed dataset. How do I do this? Dim dalc as New UserDALC Dim user As...
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to compile. <WebMethod()> _ Public Function VerifySku(ByVal skus As XmlDataDocument) As DataSet Test program : Dim cartSet As DataSet cartSet =...
by: J. Askey | last post by:
I am implementing a web service and thought it may be a good idea to return a more complex class (which I have called 'ServiceResponse') in order to wrap the original return value along with two other properties... bool error; string lastError; My whole class looks like this... using System;
by: James | last post by:
I am writing a web service for a classic ASP application. I need to consume an ADO recordset and then send it to another web service for processing. I found an MSDN ariticle telling how to do this (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconfillingdatasetwithadorecordset.asp), one big problem - it says...
by: J.C.Rivera | last post by:
Hello... I'm a rookie to c#. So let me see if i can expose properly my situation. I developed a stored procedure in sql server 2000 that allows me to construct my dataset in XML format. the sp's output will look something similar to this: <table1 column11="value111" column12="value112" column13="value113" /> <table1 column12="value121"...
by: Johnny | last post by:
I have a PocketPC mobile application that gets its data from the Sql Server database via a web service. The web service returns a dataset that I need to load into the SqlCe database on the mobile device. I have a method to perform this task but it doesn't load the data into the SqlCe database. The data is downloaded into the dataset from...
by: David | last post by:
Hi, (Sorry for duplicate post, finger trouble before I finished...) using C# 1.1 I am writing a winform app that collects a dataset from a webservice. At the same time I collect the data, I write the dataset out to the local disk using DataSet.WriteXml, so that if the webservice is not available,
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.