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: , , , , , ,

How to convert dataset to xml string with embedded schema

I have been trying to find a way to get an xml string with embedded schema from a dataset.

I know that you can use the .getxml and .getschema functions on the dataset but I do not see an easy way of combining those two results into one valid xml string.

I can't save anything to disk, everything has to happen in memory. I thought of using the .writexml method but you cannot use .writexml and pass a string...

Thank you for any thoughts you might have to solve this problem I am having.

Robertmaybe u can use the XmlSerializer object?

Labels: , , , , , , , , ,