Using xml in a data set (ADO.NET)Presentation Transcript
Using XML in a DataSet (ADO.NET) Ringo Ray H Piedraverde (Jr. Programmer)
Topics• Writing DataSet Contents as XML Data (ADO.NET)• Loading a DataSet from XML (ADO.NET)
Writing DataSet Contents as XML Data (ADO.NET)• WriteScheme Method – Writes the current contents of the DataSet as XML data with the relational structure as inline XML Schema.• WriteXml method – Using this method you can write the Dataset to a file, stream, or XmlWriter.
Code SnippetDim mds As DataSet = mds.tables(“tblUser”)mUserDS.WriteXml(“User.xml", XmlWriteMode.WriteSchema)
Loading a DataSet from XML (ADO.NET)• To fill a DataSet with data from XML, use the ReadXml method of the DataSet object. The ReadXml method reads from a file, a stream, or an XmlReader, and takes as arguments the source of the XML.• The ReadXml method reads the contents of the XML stream or document and loads the DataSet with data. It will also create the relational schema of the DataSet depending on the XmlReadMode specified and whether or not a relational schema already exists.
Code snippetDim m_Ds as DatasetPublic sub ReadXML()m_User.ReadXml(“User.xml", XmlReadMode.ReadSchema)End Sub