473,383 Members | 1,963 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,383 software developers and data experts.

"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 34569
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.si> 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*******@acadx.com> wrote in message
news:%2****************@TK2MSFTNGP09.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
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...
14
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...
0
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...
0
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. ...
4
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...
0
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...
0
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...
5
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...
6
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.