I have a DataRow dr generated from an old DataTable A. Now I want to add it into a new DataTable B. A has same structure with B. I use for() to clone a new DataRow. I wonder a good method to achieve it.
if (hour != this.currentHour)
{
ds.Tables.Add(this.currentDataTable);
this.currentHour = hour;
this.currentDataTable = InitMeasurementTable();
this.currentDataTable.TableName = string.Format("Measurement_{0}", hour);
DataRow drr = this.currentDataTable.NewRow();
for (int i = 0; i < this.currentDataTable.Columns.Count; ++i)
drr[i] = dr[i]; // clone part
this.currentDataTable.Rows.Add(drr);
}
You can use DataRow.ItemArray property.