By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,805 Members | 1,640 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,805 IT Pros & Developers. It's quick & easy.

"This row already belongs to another table" error

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.