If Program The returned datatable is added to a custom dataset. The ds. Tables. Add (DT) method is used directly, and the error "This datatable already belongs to another dataset" is displayed. At this time, we need to create a new able and import the structure and data of the original datatable to the new datatable. At this time, we can use the following method (of course, the method is not the only one):
/**/ /// <Summary>
/// Copy datatable
/// </Summary>
/// <Param name = "copydt"> Data Source </Param>
/// <Param name = "tablename"> New able name </Param>
/// <Returns> Replicated able </Returns>
Private Datatable copydatatable (datatable copydt, String Tablename)
{
Datatable dt = New Datatable (tablename );
Foreach (Datacolumn columm In Copydt. columns)
{
DT. Columns. Add (columm. columnname, columm. datatype );
}
Foreach (Datarow row In Copydt. Rows)
{
DT. begininit ();
DT. importrow (ROW );
DT. endinit ();
}
Return DT;
}