Posted By

sekihin on 05/09/11


Tagged

c#


Versions (?)

a deep copy of a datatable


 / Published in: C#
 

  1. public DataTable DeepCopy(DataTable TargetTable)
  2. {
  3.  
  4. DataTable copyTable = null;
  5.  
  6. System.IO.MemoryStream stream = new System.IO.MemoryStream();
  7.  
  8. // コピー元オブジェクトをシリアライズします。
  9.  
  10. System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
  11.  
  12. formatter.Serialize(stream, TargetTable);
  13.  
  14. stream.Position = 0;
  15.  
  16. // シリアライズデータをコピー先オブジェクトにデシリアライズします。
  17.  
  18. copyTable = (DataTable)formatter.Deserialize(stream);
  19.  
  20. return copyTable;
  21.  
  22. }

Report this snippet  

You need to login to post a comment.