質問するログイン新規登録

回答編集履歴

2

追記

2019/05/21 08:05

投稿

Zuishin
Zuishin

スコア28675

answer CHANGED
@@ -27,4 +27,6 @@
27
27
  }
28
28
  ```
29
29
 
30
- DataSet.Copy のソースです。御覧の通り、中で Clone した後、データをコピーしています。
30
+ DataSet.Copy のソースです。御覧の通り、中で Clone した後、データをコピーしています。
31
+
32
+ EnforceConstraints はデータの制約を有効にするかどうかを指定するプロパティです。これを無効にしておかないとコピーに失敗することがあるので、一時的に false にしています。制約については「データベース 制約」でググってください。

1

インデント

2019/05/21 08:05

投稿

Zuishin
Zuishin

スコア28675

answer CHANGED
@@ -6,26 +6,25 @@
6
6
  IntPtr hscp;
7
7
  Bid.ScopeEnter(out hscp, "<ds.DataSet.Copy|API> %d#\n", ObjectID);
8
8
  try {
9
- DataSet dsNew = Clone();
9
+ DataSet dsNew = Clone();
10
- bool fEnforceConstraints = dsNew.EnforceConstraints;
10
+ bool fEnforceConstraints = dsNew.EnforceConstraints;
11
- dsNew.EnforceConstraints = false;
11
+ dsNew.EnforceConstraints = false;
12
- foreach (DataTable table in this.Tables)
12
+ foreach (DataTable table in this.Tables)
13
- {
13
+ {
14
- DataTable destTable = dsNew.Tables[table.TableName, table.Namespace];
14
+ DataTable destTable = dsNew.Tables[table.TableName, table.Namespace];
15
-
15
+
16
- foreach (DataRow row in table.Rows)
16
+ foreach (DataRow row in table.Rows)
17
- table.CopyRow(destTable, row);
17
+ table.CopyRow(destTable, row);
18
- }
18
+ }
19
-
19
+
20
- dsNew.EnforceConstraints = fEnforceConstraints;
20
+ dsNew.EnforceConstraints = fEnforceConstraints;
21
-
21
+
22
- return dsNew;
22
+ return dsNew;
23
23
  }
24
24
  finally {
25
- Bid.ScopeLeave(ref hscp);
25
+ Bid.ScopeLeave(ref hscp);
26
26
  }
27
27
  }
28
-
29
28
  ```
30
29
 
31
30
  DataSet.Copy のソースです。御覧の通り、中で Clone した後、データをコピーしています。