473,804 Members | 3,469 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"This row already belongs to another table" error

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

here's the problem... I load the dataSet with all possible entries at
Form_Load event...
but during the search I don't want to change the initial dataSet, so I have
created:
tempDataSet = new DataSet();
/* fill code for tempDataSet goes here */

I also created a SqlCommand and other stuff in order to fill the values in
tempDataSet... the where clause in this
select statement is always false so I just get the right schema in the
tempDataSet...

now I try to loop through the initial dataset and find the correct rows in
this dataSet... if a match is found
I try to add that row to tempDataSet but I get the above error...

and ideas?

thanks,
saso
Nov 15 '05 #1
4 34584
The problem is in your fill code. You need to declare a new datarow object
and assign the values to that new row then add the row.

DataRow myRow = dsNew.Tables[0].NewRow();

myRow[3]= "00000.00";

myRow[2]= "00000.00";

myRow[1]= dsDonor.Tables[0].Rows[0][col].ToString();

myRow[0]= dsDonor.Tables[0].Columns[col].ColumnName;
dsNew.Tables[0].Rows.Add(myRow );

roughly

You are getting this error because the row you are adding belongs to the
donor datarow. To avoid problems with circular reference, the run-time does
not allow you to do that.

regards

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
"Saso Zagoranski" <sa************ *@guest.arnes.s i> wrote in message
news:bo******** **@planja.arnes .si...
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...

here's the problem... I load the dataSet with all possible entries at
Form_Load event...
but during the search I don't want to change the initial dataSet, so I have created:
tempDataSet = new DataSet();
/* fill code for tempDataSet goes here */

I also created a SqlCommand and other stuff in order to fill the values in
tempDataSet... the where clause in this
select statement is always false so I just get the right schema in the
tempDataSet...

now I try to loop through the initial dataset and find the correct rows in
this dataSet... if a match is found
I try to add that row to tempDataSet but I get the above error...

and ideas?

thanks,
saso

Nov 15 '05 #2
Saso Zagoranski wrote:
I also created a SqlCommand and other stuff in order to fill the
values in tempDataSet... the where clause in this
select statement is always false so I just get the right schema in the
tempDataSet...
If all you want is an existing table's schema, use the Clone method of
the DataTable class, It returns a DataTable containing only the schema
of the original.
now I try to loop through the initial dataset and find the correct
rows in this dataSet... if a match is found
I try to add that row to tempDataSet but I get the above error...


You can't add a row from another DataTable but you can import it using
ImportRow.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
Nov 15 '05 #3
BTW, instead of jumping through these hoops you might consider using the
RowFilter property of the DataTable's DefaultView member. This member is
a DataView object and they're quite handy.

Set your grid's DataSource property to your table's DataView and you can
quickly sort and filter records using only a single DataTable.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
Nov 15 '05 #4
Thanks!

That was real useful advice...

saso

"Frank Oquendo" <fr*******@acad x.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
BTW, instead of jumping through these hoops you might consider using the
RowFilter property of the DataTable's DefaultView member. This member is
a DataView object and they're quite handy.

Set your grid's DataSource property to your table's DataView and you can
quickly sort and filter records using only a single DataTable.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)

Nov 15 '05 #5

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

Similar topics

2
8689
by: Robin Tucker | last post by:
I have some code that dynamically creates a database (name is @FullName) and then creates a table within that database. Is it possible to wrap these things into a transaction such that if any one of the following fails, the database "creation" is rolledback. Otherwise, I would try deleting on error detection, but it could get messy. IF @Error = 0 BEGIN SET @ExecString = 'CREATE DATABASE ' + @FullName EXEC sp_executesql @ExecString
14
2266
by: Ernst Murnleitner | last post by:
Dear Readers, Is it possible to forbid conversion from this or use of this in general except where it is explicitly wanted? Reason: I changed my program from using normal pointers to classes A, ... typedef A * APtr;
0
4355
by: Colleyville Alan | last post by:
My app is giving me this error. Run-time error 3211: The database engine could not lock table 'Sorted_Template' because it is already in use by another person or process. When I run the app the first time through, it runs fine. I get this when I run a make-table query that tries to write out the table called "Sorted_Template". I tried using a TableDefs.Delete command thinking that make using the docmd.openquery was causing the...
0
2286
by: Richard Sherratt | last post by:
Something to add to your trivia bank. I've seen previous questions on this error but they've all been for adding new records to the RecordsetClone. I got it trying to edit an existing record. I have a "Roles" subform on a Job form where employees are assigned to jobs with the roles being "lead architect", "landscape architect", etc. The table being updated has EmployeeID, RoleID, StartDate, EndDate, etc.
4
1334
by: Richard | last post by:
When I reference "this" in call to event, I get the following error: An unhandled exception of type 'System.NullReferenceException' occurred in csbasesockets.dll Additional information: Object reference not set to an instance of an object. Here is a summary of my code:
0
1555
by: Neal | last post by:
I am getting the "This type of page is not served." error the first time I access our asp.net site after an application restart. I can hit refresh and it will work fine the second and every other time. This behavior just recently started and we can't figure out why it started. This is an application that has been working correctly without ever getting this error. Can someone point me in the right direction?
0
1444
by: gahagan | last post by:
If you encounter this error, most likely one of the controls you're trying to cut/paste is a combo box with a longer-than-average 'Row Source' value. That, apparently, is the problem. Shorter Row Source values don't seem to be a problem. (I don't have time to figure out at what length the error triggers.) Workaround: Remove the Row Source (you can cut/paste the text somewhere else), then try cutting/pasting the control(s) again. Then...
5
5583
by: darrel | last post by:
We're getting this error on a page that uses a particular User Control we created: "An Error has Occured retrieving the news item. Attempted to read or write protected memory. This is often an indication that other memory is corrupt." Googling this seems to turn up a random assortment of potential causes. What is odd is that in our situation, I can compile it on my machine and it
6
2328
by: babakandme | last post by:
Hi to every body...:D I'm a novice C++ programmer & I've a question, I have the ClassA & in it's constructor, I instantiate ClassB, and I want send "this" pointer """pointer to ClassA""" to the ClassB. But I get this Error from the compiler: and it's in ClassB... Error from the compiler: error C2061: syntax error : identifier 'TestA' error C2143: syntax error : missing ';' before '*'
0
9708
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, 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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9588
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10327
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
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 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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7625
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2999
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.