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