We have no idea where
dt1
and
dt2
came from - there is no need to clone your datatable to get at the data, just loop through your existing rows and add new rows to the end of table for each of the existing rows.
You need to capture the current size of the datatable and not use
dt.Rows.Count
in your for loop - why? Because you are going to add more rows to your datatable.
Your code could look like this
using System;
using System.Data;
public class Program
{
public static void Main()
{
Demo d = new Demo();
DataTable dt = d.createDt("demo");
int dtsize = dt.Rows.Count;
for (int k = 0; k < dtsize; k++)
{
DataRow dr;
dr = dt.NewRow();
dr["name"] = dt.Rows[k]["mark"];
dt.Rows.Add(dr);
}
for (int k = 0; k < dt.Rows.Count; k++)
Console.WriteLine("{0} : {1}\n", k, dt.Rows[k]["name"]);
}
}
A word of warning about the line
dr["name"] = dt.Rows[k]["mark"];
If you have created your DataTable with the marks column as an integer then you should really convert the mark to a string before inserting it into a name i.e.
dr["name"] = dt.Rows[k]["mark"].ToString();