locked
How can I copy datacolumn from one datatable into another datatable? RRS feed

  • Question

  • User1922557041 posted
    I got a error when copying a datacolumn from one datatable A and put into another datatable B.
    The error shows:
    The datacolumn already belogns to datatable A

    Can anyone help me?
    Wednesday, June 22, 2005 9:18 AM

All replies

  • User-738568203 posted
    you can't do that. you can do it manually though.. in datatableB, add a DataColumn of Type and length same as datatable A. then loop through and copy values.
    Wednesday, June 22, 2005 10:02 AM
  • User668733054 posted

     Do not use directly the source column name, write it by urself---

    DataTable dtDest = new DataTable();

    dtDest.Columns.Add("COLNAME");

     foreach (DataRow drCopy in Source.Rows)

    { dtDest.Rows.Add(drCopy["COLNAME"]);

     }

    Monday, December 27, 2010 2:17 AM
  • User668733054 posted

     Do not use directly the source column name, write it by urself---

    DataTable dtDest = new DataTable();

    dtDest.Columns.Add("COLNAME");

     foreach (DataRow drCopy in Source.Rows)

    { dtDest.Rows.Add(drCopy["COLNAME"]);

     }

    Thanks

    Veenu Goel

     

    Monday, December 27, 2010 2:17 AM