回答編集履歴

2

追記

2019/05/21 08:05

投稿

Zuishin
Zuishin

スコア28660

test CHANGED
@@ -57,3 +57,7 @@
57
57
 
58
58
 
59
59
  DataSet.Copy のソースです。御覧の通り、中で Clone した後、データをコピーしています。
60
+
61
+
62
+
63
+ EnforceConstraints はデータの制約を有効にするかどうかを指定するプロパティです。これを無効にしておかないとコピーに失敗することがあるので、一時的に false にしています。制約については「データベース 制約」でググってください。

1

インデント

2019/05/21 08:05

投稿

Zuishin
Zuishin

スコア28660

test CHANGED
@@ -14,45 +14,43 @@
14
14
 
15
15
  try {
16
16
 
17
- DataSet dsNew = Clone();
17
+ DataSet dsNew = Clone();
18
18
 
19
- bool fEnforceConstraints = dsNew.EnforceConstraints;
19
+ bool fEnforceConstraints = dsNew.EnforceConstraints;
20
20
 
21
- dsNew.EnforceConstraints = false;
21
+ dsNew.EnforceConstraints = false;
22
22
 
23
- foreach (DataTable table in this.Tables)
23
+ foreach (DataTable table in this.Tables)
24
24
 
25
- {
25
+ {
26
26
 
27
- DataTable destTable = dsNew.Tables[table.TableName, table.Namespace];
27
+ DataTable destTable = dsNew.Tables[table.TableName, table.Namespace];
28
28
 
29
+
29
30
 
31
+ foreach (DataRow row in table.Rows)
30
32
 
31
- foreach (DataRow row in table.Rows)
33
+ table.CopyRow(destTable, row);
32
34
 
33
- table.CopyRow(destTable, row);
35
+ }
34
36
 
35
- }
37
+
36
38
 
39
+ dsNew.EnforceConstraints = fEnforceConstraints;
37
40
 
41
+
38
42
 
39
- dsNew.EnforceConstraints = fEnforceConstraints;
40
-
41
-
42
-
43
- return dsNew;
43
+ return dsNew;
44
44
 
45
45
  }
46
46
 
47
47
  finally {
48
48
 
49
- Bid.ScopeLeave(ref hscp);
49
+ Bid.ScopeLeave(ref hscp);
50
50
 
51
51
  }
52
52
 
53
53
  }
54
-
55
-
56
54
 
57
55
  ```
58
56