In the course of our work, it is possible to use a DataTable to produce some duplicate data (without repeatedly reading the database)
No nonsense, directly on the code
The DataTable replicates its own row (for the purpose of generating duplicate data), which has been tested by directly replicating
1 /// <summary>2 ///Create a DataTable and generate test data3 /// </summary>4 /// <returns></returns>5 Public StaticDataTable Createdtdata (intargrownum)6 {7DataTable dt =NewDataTable ();8Dt. Columns.Add ("ID");9Dt. Columns.Add ("Name");TenDt. Columns.Add ("Sex"); OneDt. Columns.Add (" Age"); A - inti =0; - for(; i < argrownum; i++) the { -DataRow dr =dt. NewRow (); -dr[0] =i; -dr[1] ="LD"+i; +dr[2] ="male"; -dr[3] = i *6; + dt. Rows.Add (DR); A } at - returnDT; - } - Static voidMain (string[] args) - { -Console.WriteLine ("1. Create a DataTable 10 row"); inDataTable Dtsource = Createdtdata (Ten); -Console.WriteLine ("2. Copy data by default is the first line"); toDtsource.importrow (dtsource.rows[0]); +Dtsource.rows[dtsource.rows.count-1][1] ="Test"; - theConsole.WriteLine (dtsource.rows[0][1]. ToString ()); *Console.WriteLine (Dtsource.rows[dtsource.rows.count-1][1]. ToString ()); $ Panax Notoginseng Console.read (); -}View Code
Note:
The main idea is to use a DataTable function ImportRow (the function is to copy a row, not copy the reference, is to copy the data);
where Dtsource.importrow (Dtsource.rows[0]), can be replaced by DTSOURCE.ROWS.ADD (Dtsource.rows[0]. ItemArray);
Reference: http://blog.sina.com.cn/s/blog_75a555e401014rid.html
DataTable copies itself rows