Wrox Home  
Search P2P Archive for: Go

  Return to Index  

ado_dotnet thread: DataTable[] concatenated to DataTable


Message #1 by "David Garner" <dgarner@g...> on Fri, 17 May 2002 21:16:54
I have an array of DataTable objects all with the exact same schema.  I 
want to concatenate these into one DataTable. Here's what I tried....

// each DataTable in the array has the exact same schema.
// tableArray[] is an array of DataTable
DataTable wholeTable = new DataTable();
DataRow dr;
foreach ( DataTable dt in tableArray )
{
	for ( int y = 0; y < dt.Rows.Count; y++ )
	{
		dr = dt.Rows[y];
		wholeTable.Rows.Add( dr );
		// ERROR: the line above throws and exception claiming the 
		// data row cannot be added because it already belongs
		// to another table.
	}
}

Any suggestions?
Message #2 by schmidtj@c... on Fri, 17 May 2002 16:12:50 -0400
look at the "ImportRow" method for the datatable.  This is what you 
need.

-----Original Message-----
From: David Garner [mailto:dgarner@g...]
Sent: Friday, May 17, 2002 5:17 PM
To: ADO.NET
Subject: [ado_dotnet] DataTable[] concatenated to DataTable


I have an array of DataTable objects all with the exact same schema.  I
want to concatenate these into one DataTable. Here's what I tried....

// each DataTable in the array has the exact same schema.
// tableArray[] is an array of DataTable
DataTable wholeTable =3D new DataTable();
DataRow dr;
foreach ( DataTable dt in tableArray )
{
	for ( int y =3D 0; y < dt.Rows.Count; y++ )
	{
		dr =3D dt.Rows[y];
		wholeTable.Rows.Add( dr );
		// ERROR: the line above throws and exception claiming the
		// data row cannot be added because it already belongs
		// to another table.
	}
}

Any suggestions?
Message #3 by "David Garner" <dgarner@g...> on Fri, 17 May 2002 21:30:18
You rock.  That worked perfectly.

  Return to Index