■ 데이터 테이블을 복사하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
using System.Data; #region 복사하기 - Copy(sourceTable, targetTable) /// <summary> /// 복사하기 /// </summary> /// <param name="sourceTable">소스 테이블</param> /// <param name="targetTable">타겟 테이블</param> public void Copy(DataTable sourceTable, ref DataTable targetTable) { targetTable = sourceTable.Clone(); for(int i = 0; i < sourceTable.Rows.Count; i++) { object array = sourceTable.Rows[i].ItemArray.Clone(); DataRow targetRow = targetTable.NewRow(); targetRow.ItemArray = (object[])array; targetTable.Rows.Add(targetRow); } } #endregion |