473,396 Members | 1,738 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.

: an exception raised

Hello,

Dim row As DataRow
Dim column As DataColumn
For Each row In myDTSrc.Rows
For Each column In myDTSrc.Columns
myRowDest(column.ColumnName.ToString) =
row(column.ColumnName.ToString)
Next
myDTDest.Rows.Add(myRowDest)
myDA.Update(myDTDest)
myDTDest.AcceptChanges()
Next

This code adds first row from MyDTSrc to myDTDest which is attached an SQL
table, but at the second row I get exception "This row already belongs to
this table", what is problem?
Thanks,
Jim.

Nov 19 '05 #1
9 860
Try this:

Dim row As DataRow
Dim column As DataColumn
For Each row In myDTSrc.Rows
myRowDest = myDTDest.NewRow
For Each column In myDTSrc.Columns
myRowDest(column.ColumnName.ToString) =
row(column.ColumnName.ToString)
Next
myDTDest.Rows.Add(myRowDest)

Next
myDA.Update(myDTDest)
myDTDest.AcceptChanges()

Nov 19 '05 #2
Jim,
The error pretty clearly states what the problem is. A datarow can only
belong to 1 datatable....remember all these are references so all you are
copying is the reference to the same datarow...

Why not just do:

myDtDest = myDtSrc.Copy(); ??

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:40**********************************@microsof t.com...
Hello,

Dim row As DataRow
Dim column As DataColumn
For Each row In myDTSrc.Rows
For Each column In myDTSrc.Columns
myRowDest(column.ColumnName.ToString) =
row(column.ColumnName.ToString)
Next
myDTDest.Rows.Add(myRowDest)
myDA.Update(myDTDest)
myDTDest.AcceptChanges()
Next

This code adds first row from MyDTSrc to myDTDest which is attached an SQL
table, but at the second row I get exception "This row already belongs to
this table", what is problem?
Thanks,
Jim.

Nov 19 '05 #3
Jim,

You need to create new myRowDest in every loop.

Eliyahu

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:40**********************************@microsof t.com...
Hello,

Dim row As DataRow
Dim column As DataColumn
For Each row In myDTSrc.Rows
For Each column In myDTSrc.Columns
myRowDest(column.ColumnName.ToString) =
row(column.ColumnName.ToString)
Next
myDTDest.Rows.Add(myRowDest)
myDA.Update(myDTDest)
myDTDest.AcceptChanges()
Next

This code adds first row from MyDTSrc to myDTDest which is attached an SQL
table, but at the second row I get exception "This row already belongs to
this table", what is problem?
Thanks,
Jim.

Nov 19 '05 #4
Thanks Karl, I did,
myDTDest = myDTSrc.Copy()
myDA.Update(myDTDest)
but I do nto see data in table. What might be the problem?

"Karl Seguin" wrote:
Jim,
The error pretty clearly states what the problem is. A datarow can only
belong to 1 datatable....remember all these are references so all you are
copying is the reference to the same datarow...

Why not just do:

myDtDest = myDtSrc.Copy(); ??

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:40**********************************@microsof t.com...
Hello,

Dim row As DataRow
Dim column As DataColumn
For Each row In myDTSrc.Rows
For Each column In myDTSrc.Columns
myRowDest(column.ColumnName.ToString) =
row(column.ColumnName.ToString)
Next
myDTDest.Rows.Add(myRowDest)
myDA.Update(myDTDest)
myDTDest.AcceptChanges()
Next

This code adds first row from MyDTSrc to myDTDest which is attached an SQL
table, but at the second row I get exception "This row already belongs to
this table", what is problem?
Thanks,
Jim.


Nov 19 '05 #5

Thanks Eliyahu,
I did this, and I am wondering if this will cause any overflow problem
because of a new decleration for each row. It might be a big table.

Dim row As DataRow
Dim column As DataColumn
For Each row In myDTSrc.Rows Dim myRowDest As DataRow = myDTDest.NewRow For Each column In myDTSrc.Columns
myRowDest(column.ColumnName.ToString) => row(column.ColumnName.ToString)
Next
myDTDest.Rows.Add(myRowDest)
myDA.Update(myDTDest)
myDTDest.AcceptChanges()
Next
"Eliyahu Goldin" wrote:
Jim,

You need to create new myRowDest in every loop.

Eliyahu

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:40**********************************@microsof t.com...
Hello,

Dim row As DataRow
Dim column As DataColumn
For Each row In myDTSrc.Rows
For Each column In myDTSrc.Columns
myRowDest(column.ColumnName.ToString) =
row(column.ColumnName.ToString)
Next
myDTDest.Rows.Add(myRowDest)
myDA.Update(myDTDest)
myDTDest.AcceptChanges()
Next

This code adds first row from MyDTSrc to myDTDest which is attached an SQL
table, but at the second row I get exception "This row already belongs to
this table", what is problem?
Thanks,
Jim.


Nov 19 '05 #6
This is how it HAS to be. Every row HAS to be a separate object.

Eliyahu

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...

Thanks Eliyahu,
I did this, and I am wondering if this will cause any overflow problem
because of a new decleration for each row. It might be a big table.

Dim row As DataRow
Dim column As DataColumn
For Each row In myDTSrc.Rows

Dim myRowDest As DataRow = myDTDest.NewRow
For Each column In myDTSrc.Columns
myRowDest(column.ColumnName.ToString) => row(column.ColumnName.ToString) Next
myDTDest.Rows.Add(myRowDest)
myDA.Update(myDTDest)
myDTDest.AcceptChanges()
Next


"Eliyahu Goldin" wrote:
Jim,

You need to create new myRowDest in every loop.

Eliyahu

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:40**********************************@microsof t.com...
Hello,

Dim row As DataRow
Dim column As DataColumn
For Each row In myDTSrc.Rows
For Each column In myDTSrc.Columns
myRowDest(column.ColumnName.ToString) =
row(column.ColumnName.ToString)
Next
myDTDest.Rows.Add(myRowDest)
myDA.Update(myDTDest)
myDTDest.AcceptChanges()
Next

This code adds first row from MyDTSrc to myDTDest which is attached an SQL table, but at the second row I get exception "This row already belongs to this table", what is problem?
Thanks,
Jim.


Nov 19 '05 #7
I am new in asp.net, so if there is 5000 object is created in that function,
will it cause any problem? I assume the object life will end when the
function ends.

"Eliyahu Goldin" wrote:
This is how it HAS to be. Every row HAS to be a separate object.

Eliyahu

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...

Thanks Eliyahu,
I did this, and I am wondering if this will cause any overflow problem
because of a new decleration for each row. It might be a big table.

Dim row As DataRow
Dim column As DataColumn
For Each row In myDTSrc.Rows

Dim myRowDest As DataRow = myDTDest.NewRow
For Each column In myDTSrc.Columns
myRowDest(column.ColumnName.ToString) => row(column.ColumnName.ToString) Next
myDTDest.Rows.Add(myRowDest)
myDA.Update(myDTDest)
myDTDest.AcceptChanges()
Next


"Eliyahu Goldin" wrote:
Jim,

You need to create new myRowDest in every loop.

Eliyahu

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:40**********************************@microsof t.com...
> Hello,
>
> Dim row As DataRow
> Dim column As DataColumn
> For Each row In myDTSrc.Rows
> For Each column In myDTSrc.Columns
> myRowDest(column.ColumnName.ToString) =
> row(column.ColumnName.ToString)
> Next
> myDTDest.Rows.Add(myRowDest)
> myDA.Update(myDTDest)
> myDTDest.AcceptChanges()
> Next
>
> This code adds first row from MyDTSrc to myDTDest which is attached an SQL > table, but at the second row I get exception "This row already belongs to > this table", what is problem?
> Thanks,
> Jim.
>


Nov 19 '05 #8
It should not be any different from reading 5000 rows from a database.When
you read 5000 rows from a database, every row is represented by a separate
object. When you change one row, you wouldn't like another row to get the
same changes would you? I am not aware of any special limitation for tables.
Usual memory limitations apply. 5000 rows is not a very large table, should
be ok. Depends on row content of course.

Since you attach row objects to a table and the table persists outside the
function, the row objects will persist too.

Eliyahu

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:6C**********************************@microsof t.com...
I am new in asp.net, so if there is 5000 object is created in that function, will it cause any problem? I assume the object life will end when the
function ends.

"Eliyahu Goldin" wrote:
This is how it HAS to be. Every row HAS to be a separate object.

Eliyahu

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...

Thanks Eliyahu,
I did this, and I am wondering if this will cause any overflow problem
because of a new decleration for each row. It might be a big table.
> Dim row As DataRow
> Dim column As DataColumn
> For Each row In myDTSrc.Rows
Dim myRowDest As DataRow = myDTDest.NewRow
> For Each column In myDTSrc.Columns
> myRowDest(column.ColumnName.ToString) =>

row(column.ColumnName.ToString)
> Next
> myDTDest.Rows.Add(myRowDest)
> myDA.Update(myDTDest)
> myDTDest.AcceptChanges()
> Next

"Eliyahu Goldin" wrote:

> Jim,
>
> You need to create new myRowDest in every loop.
>
> Eliyahu
>
> "JIM.H." <JI**@discussions.microsoft.com> wrote in message
> news:40**********************************@microsof t.com...
> > Hello,
> >
> > Dim row As DataRow
> > Dim column As DataColumn
> > For Each row In myDTSrc.Rows
> > For Each column In myDTSrc.Columns
> > myRowDest(column.ColumnName.ToString) =
> > row(column.ColumnName.ToString)
> > Next
> > myDTDest.Rows.Add(myRowDest)
> > myDA.Update(myDTDest)
> > myDTDest.AcceptChanges()
> > Next
> >
> > This code adds first row from MyDTSrc to myDTDest which is
attached an SQL
> > table, but at the second row I get exception "This row already
belongs to
> > this table", what is problem?
> > Thanks,
> > Jim.
> >
>
>
>


Nov 19 '05 #9
I think there has to be a better way than copying each COLUMN BY COLUMN

TNX
Hitesh
"Eliyahu Goldin" wrote:
It should not be any different from reading 5000 rows from a database.When
you read 5000 rows from a database, every row is represented by a separate
object. When you change one row, you wouldn't like another row to get the
same changes would you? I am not aware of any special limitation for tables.
Usual memory limitations apply. 5000 rows is not a very large table, should
be ok. Depends on row content of course.

Since you attach row objects to a table and the table persists outside the
function, the row objects will persist too.

Eliyahu

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:6C**********************************@microsof t.com...
I am new in asp.net, so if there is 5000 object is created in that

function,
will it cause any problem? I assume the object life will end when the
function ends.

"Eliyahu Goldin" wrote:
This is how it HAS to be. Every row HAS to be a separate object.

Eliyahu

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
>
> Thanks Eliyahu,
> I did this, and I am wondering if this will cause any overflow problem
> because of a new decleration for each row. It might be a big table.
>
>
> > Dim row As DataRow
> > Dim column As DataColumn
> > For Each row In myDTSrc.Rows
> Dim myRowDest As DataRow = myDTDest.NewRow
> > For Each column In myDTSrc.Columns
> > myRowDest(column.ColumnName.ToString) =>
row(column.ColumnName.ToString)
> > Next
> > myDTDest.Rows.Add(myRowDest)
> > myDA.Update(myDTDest)
> > myDTDest.AcceptChanges()
> > Next
>
>
>
> "Eliyahu Goldin" wrote:
>
> > Jim,
> >
> > You need to create new myRowDest in every loop.
> >
> > Eliyahu
> >
> > "JIM.H." <JI**@discussions.microsoft.com> wrote in message
> > news:40**********************************@microsof t.com...
> > > Hello,
> > >
> > > Dim row As DataRow
> > > Dim column As DataColumn
> > > For Each row In myDTSrc.Rows
> > > For Each column In myDTSrc.Columns
> > > myRowDest(column.ColumnName.ToString) =
> > > row(column.ColumnName.ToString)
> > > Next
> > > myDTDest.Rows.Add(myRowDest)
> > > myDA.Update(myDTDest)
> > > myDTDest.AcceptChanges()
> > > Next
> > >
> > > This code adds first row from MyDTSrc to myDTDest which is attached an SQL
> > > table, but at the second row I get exception "This row already belongs to
> > > this table", what is problem?
> > > Thanks,
> > > Jim.
> > >
> >
> >
> >


Nov 19 '05 #10

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

Similar topics

8
by: StepH | last post by:
Hi, I've this module : from optparse import OptionParser import re _version = "P1" def writeVar(f, line):
5
by: juergen perlinger | last post by:
Hello out there. sometimes I need to have proper control of the floating point arithmetic of the C(and C++) runtime system, and using the f.p. exception handling of the C99 standard is quite...
1
by: Bob | last post by:
In Vs 2005 you have new applicationsEvents.vb I was testing it in a simple app and found that it was easier to implement unhandled exception management tah it was in Vs2003 (vb.net) You can, if you...
132
by: Zorro | last post by:
The simplicity of stack unraveling of C++ is not without defective consequences. The following article points to C++ examples showing the defects. An engineer aware of defects can avoid...
5
by: =?Utf-8?B?c3VydHVyeg==?= | last post by:
Hi, I feel like a noob for asking this. When I publish a VB windows application, I want to disable the ability of the the user to continue when there is an unhandled exception. For example,...
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
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...
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.