Merging Two DataTables in C#
private void MergeDataTable()
{
DataTable
dtOne = new DataTable("FirstTable");
dtOne.Columns.Add("MyColumn");
DataTable
dtTwo = new DataTable("SecondTable");
dtTwo.Columns.Add("MyColumn");
for
(int i = 1; i <= 10; i++)
{
DataRow
row = dtOne.NewRow();
row["MyColumn"]
= "Data" + i;
dtOne.Rows.Add(row);
}
for
(int i = 11; i <= 20; i++)
{
DataRow
row = dtTwo.NewRow();
row["MyColumn"]
= "Data" + i;
dtTwo.Rows.Add(row);
}
DataSet
ds = new DataSet();
ds.Tables.Add(dtOne);
ds.Merge(dtTwo);
DataGrid1.DataSource = ds;
DataGrid1.DataBind();
}