日期:2014-05-17 浏览次数:21277 次
DataTable DT1 = new DataTable(); DT1.Columns.Add("编号",typeof(int)); DT1.Columns.Add("内容",typeof(string)); DataRow rw1 = DT1.NewRow(); rw1[0] = 1; rw1[1] = "北京"; DT1.Rows.Add(rw1); DataRow rw2 = DT1.NewRow(); rw2[0] = 1; rw2[1] = "上海"; DT1.Rows.Add(rw2); DataRow rw3 = DT1.NewRow(); rw3[0] = 1; rw3[1] = "天津"; DT1.Rows.Add(rw3); DataRow rw4 = DT1.NewRow(); rw4[0] = 2; rw4[1] = "武汉"; DT4.Rows.Add(rw4); DataRow rw5 = DT1.NewRow(); rw5[0] = 2; rw5[1] = "广州"; DT1.Rows.Add(rw5); DataRow rw6 = DT1.NewRow(); rw6[0] = 2; rw6[1] = "深圳"; DT1.Rows.Add(rw6); DataRow rw7 = DT1.NewRow(); rw7[0] = 3; rw7[1] = "重庆"; DT1.Rows.Add(rw7); DataRow rw8 = DT1.NewRow(); rw8[0] = 3; rw8[1] = "青岛"; DT1.Rows.Add(rw8); DataRow rw9 = DT1.NewRow(); rw9[0] = 3; rw9[1] = "沈阳"; DT1.Rows.Add(rw9); for(int i=0;i<DT1.Rows.Count;i++) { if((int)DT1.Rows[i][0] != 2) { DT1.Rows[i].RemoveAt(i); } } DataTable DT2 = new DataTable(); DT2 = DT1.Copy();