datatable1
id name age
1 aa 11
2 bb 12
3 cc 12
... ... ...
要把datatable1中的Name列(包括数据)复制到 datatable2中,代码该怎么写
1 DataTable datatable1 = new DataTable(); 2 DataTable datatable2 = new DataTable(); 3 datatable1.Columns.Add("id",Type.GetType("System.Int32")); 4 datatable1.Columns.Add("name",Type.GetType("System.String")); 5 DataRow dr = datatable1.NewRow(); 6 dr["id"] = "1"; 7 dr["name"] = "aa"; 8 datatable1.Rows.Add(dr); 9 dr = datatable1.NewRow(); 10 dr["id"] = "2"; 11 dr["name"] = "bb"; 12 datatable1.Rows.Add(dr); 13 dr = datatable1.NewRow(); 14 dr["id"] = "3"; 15 dr["name"] = "cc"; 16 datatable1.Rows.Add(dr); 17 18 datatable2.Columns.Add("name",Type.GetType("System.String")); 19 DataRow dr1 = null; 20 for (int i = 0; i < datatable1.Rows.Count; i++) 21 { 22 dr1 = datatable2.NewRow(); 23 dr1["name"] = datatable1.Rows[i]["name"].ToString(); 24 datatable2.Rows.Add(dr1); 25 }
insert into table2 select * from table1
http://www.cnblogs.com/freshman0216/archive/2008/08/15/1268316.html
DataView view = _ds.Tables[0].DefaultView; _table = view.ToTable(true , “列名数组”);