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
|
private void button1_Click(object sender, EventArgs e)
{
DataSet1 ds = new DataSet1();
DataSet1.DataTable1Row row1 = ds.DataTable1.NewDataTable1Row();
DataSet1.DataTable1Row row2 = ds.DataTable1.NewDataTable1Row();
row1.Column1 = 100;
row1.Column2 = "200";
//row1.Column3 = DateTime.Now;
row2.Column1 = 200;
row2.Column3 = DateTime.Now;
CopyDataRow(row1, row2);
}
private void CopyDataRow(DataRow srcRow, DataRow dstRow)
{
for (int srcIndex = 0; srcIndex < srcRow.Table.Columns.Count; srcIndex++)
{
string colName = srcRow.Table.Columns[srcIndex].ColumnName;
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];
}
}
}
}
}
|