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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
public void test()
{
DataSet1 ds = new DataSet1();
DataSet1.DataTable1Row row1 = ds.DataTable1.NewDataTable1Row();
DataSet1.DataTable1Row row2 = ds.DataTable1.NewDataTable1Row();
List<string> col = new List<string> ();
row1.Column1 = 100;
row1.Column2 = "200";
row1.Column3 = DateTime.Now;
col.Add(ds.DataTable1.Column1Column.ColumnName);
// Column1以外の列をコピーします。
CopyDataRow(row1, row2, col);
}
/// <summary>
/// DataRowをコピーします。
/// </summary>
/// <param name="sourceRow">コピー元の行です。</param>
/// <param name="destRow">コピー先の行です。</param>
/// <param name="disableColumn">コピー対象外のカラムです。</param>
private void CopyDataRow(DataRow srcRow, DataRow dstRow, List<string> disableColumn)
{
for (int srcIndex = 0; srcIndex < srcRow.Table.Columns.Count; srcIndex++)
{
string colName = srcRow.Table.Columns[srcIndex].ColumnName;
if (disableColumn.Contains(colName)) { continue; }
for (int index = 0; index < dstRow.Table.Columns.Count; index++)
{
if (colName == dstRow.Table.Columns[index].ColumnName)
{
if (srcRow[colName] == null)
{
dstRow[colName] = null;
}
else
{
dstRow[colName] = srcRow[colName];
}
}
}
}
}
|