Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > : an exception raised

Reply
Thread Tools

: an exception raised

 
 
=?Utf-8?B?SklNLkgu?=
Guest
Posts: n/a
 
      03-02-2005
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.

 
Reply With Quote
 
 
 
 
jlien
Guest
Posts: n/a
 
      03-02-2005
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()

 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      03-02-2005
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." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      03-02-2005
Jim,

You need to create new myRowDest in every loop.

Eliyahu

"JIM.H." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
=?Utf-8?B?SklNLkgu?=
Guest
Posts: n/a
 
      03-02-2005
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." <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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.
> >

>
>
>

 
Reply With Quote
 
=?Utf-8?B?SklNLkgu?=
Guest
Posts: n/a
 
      03-02-2005

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." <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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.
> >

>
>
>

 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      03-02-2005
This is how it HAS to be. Every row HAS to be a separate object.

Eliyahu

"JIM.H." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> 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." <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > 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.
> > >

> >
> >
> >



 
Reply With Quote
 
=?Utf-8?B?SklNLkgu?=
Guest
Posts: n/a
 
      03-02-2005
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." <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >
> > 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." <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > 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.
> > > >
> > >
> > >
> > >

>
>
>

 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      03-02-2005
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." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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." <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > >
> > > 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." <(E-Mail Removed)> wrote in message
> > > > news:(E-Mail Removed)...
> > > > > 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.
> > > > >
> > > >
> > > >
> > > >

> >
> >
> >



 
Reply With Quote
 
=?Utf-8?B?SGl0ZXNo?=
Guest
Posts: n/a
 
      06-03-2005
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." <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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." <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > >
> > > > 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." <(E-Mail Removed)> wrote in message
> > > > > news:(E-Mail Removed)...
> > > > > > 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.
> > > > > >
> > > > >
> > > > >
> > > > >
> > >
> > >
> > >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Page not displaying when exception raised pbo.spam@gmail.com ASP .Net 5 11-07-2005 02:13 PM
exception raised for valid variable declaration? Carlos ASP .Net 1 02-17-2005 08:26 PM
Exception feature creep! (was: re-entering in the normal flow after an exception is raised) Lonnie Princehouse Python 8 10-02-2004 09:16 PM
capture exception raised by child thread. Joe Wong Python 1 05-14-2004 11:50 AM
Exception raised tropicoorion Python 0 02-14-2004 03:02 PM



Advertisments