由於資源文件被編譯到程序集中,因此無法寫入資源。
嘗試讀取XML文件到您的強類型數據集,使用此示例(VB.NET)...
我已經創建了兩個類型化數據集,DS1和DS2用不同的模式。我寫出了兩個示例XML數據文件,沒有他們的模式。然後我嘗試讀取文件夾中的每個xml文件以查找與我的目標強類型數據集相匹配的xml文件。如果我的目標數據集在讀取嘗試後有數據,則該模式是匹配的。
Private Const InputFolder As String = "C:\xmlinputdata\"
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
WriteTestXML()
For Each s In IO.Directory.GetFiles(InputFolder, "*.xml")
Dim dsTarget As New ds1
dsTarget.ReadXml(s, Data.XmlReadMode.IgnoreSchema)
If DatasetHasData(dsTarget) Then
MsgBox(dsTarget.GetXml)
End If
Next
End Sub
Private Function DatasetHasData(ByVal ds As Data.DataSet) As Boolean
For Each dt As Data.DataTable In ds.Tables
If dt.Rows.Count > 0 Then
Return True
End If
Next
Return False
End Function
Private Sub WriteTestXML()
Dim x As New ds1
x.dt1.Adddt1Row("A", "B")
x.dt1.Adddt1Row("C", "D")
x.WriteXml(InputFolder & "ds1.xml", Data.XmlWriteMode.IgnoreSchema)
Dim y As New ds2
With y.dt2
.Adddt2Row(1, 2, 3)
.Adddt2Row(4, 5, 6)
End With
y.WriteXml(InputFolder & "ds2.xml", Data.XmlWriteMode.IgnoreSchema)
End Sub