Monday, March 12, 2012

How to copy a row from one DataTable to another DataTable?

Hi all,
Assume that both DataTable are the same schema, I want to copy a row from
one DataTable to another DataTable by
m_dtItem.Rows.Add(m_dtOrgItem.Rows(0))
However, it said that
Exception Details: System.ArgumentException: This row already belongs to
another table.
So, How can copy a row from one DataTable to another DataTable?
Thank you.use m_dtItem.ImportRow instead of m_dtItem.Rows.Add
"angus" <angus@.angus.com> wrote in message
news:ODVqYLWwEHA.1292@.TK2MSFTNGP10.phx.gbl...
> Hi all,
> Assume that both DataTable are the same schema, I want to copy a row from
> one DataTable to another DataTable by
> m_dtItem.Rows.Add(m_dtOrgItem.Rows(0))
> However, it said that
> Exception Details: System.ArgumentException: This row already belongs to
> another table.
> So, How can copy a row from one DataTable to another DataTable?
> Thank you.
>
Hi -
You have to use the ItemArray to copy the row
m_dtItem.Rows.Add(m_dtOrgItem.Rows(0).ItemArray)
Shankar
11/3/2004 10:36:04 AM
angus <angus@.angus.com> wrote in message
<ODVqYLWwEHA.1292@.TK2MSFTNGP10.phx.gbl>
> Hi all,
> Assume that both DataTable are the same schema, I want to copy a
row from
> one DataTable to another DataTable by
> m_dtItem.Rows.Add(m_dtOrgItem.Rows(0))
> However, it said that
> Exception Details: System.ArgumentException: This row already
belongs to
> another table.
> So, How can copy a row from one DataTable to another DataTable?
> Thank you.
Right
To prevent that everybody reads everything again and againg
:-)
> use m_dtItem.ImportRow instead of m_dtItem.Rows.Add
>

Labels: , , , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home