2008年3月19日水曜日

[VB] リソースのXMLをデータセットに読み込ませる

テストデータなんかをXMLに書いておいて、読み込ませる時に使ってます。

--------------------------

  1. ' 現在実行中のアセンブリを取得  
  2. Dim asm As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()  
  3.   
  4. 'アセンブリ中のすべての名称を取得  
  5. Dim rns() As String = asm.GetManifestResourceNames()  
  6. If (rns.Length <= 0) Then  
  7.    Return Nothing  
  8. End If  
  9.   
  10. ' リソースのストリームを取得  
  11. Dim s As IO.Stream = asm.GetManifestResourceStream(rns(0))  
  12.   
  13. 'データセットに読み込ませる  
  14. Dim ds As New DataSet  
  15. ds.ReadXml(s)  

0 件のコメント: