How to read into DataSetName from XML file using ReadXML () in .Net?

I wrote a DataSet to XML file using .WriteXML (FileName) and the dataset's DataSetName property is the top level tag in the file. However, when I try to read a file into another DataSet using .ReadXML (FileName), the DataSetName is not changed to the top-level tag value. Am I doing something wrong, or should ReadXML not be setting the DataSetName? It just amazes me how strange it is that he writes it down but doesn't read it.

Here's my writing code, XML file and reading code:

Record:

dsNewReport.DataSetName = "Rejected"
dsNewReport.WriteXml(My.Application.Info.DirectoryPath & "/Reports/Incomplete/" & fileName)

      

The resulting XML:

<?xml version="1.0" standalone="yes"?>
<Rejected>
  <SearchData>
  //SNIP
  </SearchData>
</Rejected>

      

Reading:

dsSearchReport.ReadXml(My.Application.Info.DirectoryPath & "/Reports/Incomplete/Search_" & Search_SEQ_GUID & ".xml")
If dsSearchReport.DataSetName = "Rejected" Then
    return True
    'DataSetName = dsSearchReport after the read      
End IF

      

+2


source to share


1 answer


ReadXml is not intended or is not set with customizing your DataSet name - you will have to do it yourself.

Of course - in your case you want to set it to the root level name, but that might not be what everyone wants. Someone might want to set it to a filename - or even something completely different.



So, as a tradeoff, the ReadXml function does nothing - it won't touch your DataSet name in any way, shape or form. There is no mistake on your part - as it is.

Mark

+2


source







All Articles