: an exception raised

Discussion in 'ASP .Net' started by =?Utf-8?B?SklNLkgu?=, Mar 2, 2005.

  1. 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.
     
    =?Utf-8?B?SklNLkgu?=, Mar 2, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?SklNLkgu?=

    jlien Guest

    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()
     
    jlien, Mar 2, 2005
    #2
    1. Advertising

  3. =?Utf-8?B?SklNLkgu?=

    Karl Seguin Guest

    Re: an exception raised

    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." <> wrote in message
    news:...
    > 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.
    >
     
    Karl Seguin, Mar 2, 2005
    #3
  4. Re: an exception raised

    Jim,

    You need to create new myRowDest in every loop.

    Eliyahu

    "JIM.H." <> wrote in message
    news:...
    > 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.
    >
     
    Eliyahu Goldin, Mar 2, 2005
    #4
  5. Re: an exception raised

    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." <> wrote in message
    > news:...
    > > 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.
    > >

    >
    >
    >
     
    =?Utf-8?B?SklNLkgu?=, Mar 2, 2005
    #5
  6. Re: an exception raised

    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." <> wrote in message
    > news:...
    > > 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.
    > >

    >
    >
    >
     
    =?Utf-8?B?SklNLkgu?=, Mar 2, 2005
    #6
  7. Re: an exception raised

    This is how it HAS to be. Every row HAS to be a separate object.

    Eliyahu

    "JIM.H." <> wrote in message
    news:...
    >
    > 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." <> wrote in message
    > > news:...
    > > > 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.
    > > >

    > >
    > >
    > >
     
    Eliyahu Goldin, Mar 2, 2005
    #7
  8. Re: an exception raised

    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." <> wrote in message
    > news:...
    > >
    > > 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." <> wrote in message
    > > > news:...
    > > > > 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.
    > > > >
    > > >
    > > >
    > > >

    >
    >
    >
     
    =?Utf-8?B?SklNLkgu?=, Mar 2, 2005
    #8
  9. Re: an exception raised

    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." <> wrote in message
    news:...
    > 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." <> wrote in message
    > > news:...
    > > >
    > > > 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." <> wrote in message
    > > > > news:...
    > > > > > 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.
    > > > > >
    > > > >
    > > > >
    > > > >

    > >
    > >
    > >
     
    Eliyahu Goldin, Mar 2, 2005
    #9
  10. Re: an exception raised

    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." <> wrote in message
    > news:...
    > > 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." <> wrote in message
    > > > news:...
    > > > >
    > > > > 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." <> wrote in message
    > > > > > news:...
    > > > > > > 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.
    > > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > >
    > > >
    > > >

    >
    >
    >
     
    =?Utf-8?B?SGl0ZXNo?=, Jun 3, 2005
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Carlos
    Replies:
    1
    Views:
    365
    Wilco Bauwer
    Feb 17, 2005
  2. Replies:
    5
    Views:
    449
  3. tropicoorion

    Exception raised

    tropicoorion, Feb 14, 2004, in forum: Python
    Replies:
    0
    Views:
    305
    tropicoorion
    Feb 14, 2004
  4. Joe Wong
    Replies:
    1
    Views:
    470
    Ype Kingma
    May 14, 2004
  5. Lonnie Princehouse
    Replies:
    8
    Views:
    542
    Lonnie Princehouse
    Oct 2, 2004
Loading...

Share This Page