Using xml in a data set (ADO.NET)

9
Using XML in a DataSet (ADO.NET) Ringo Ray H Piedraverde (Jr. Programmer)

Transcript of Using xml in a data set (ADO.NET)

Page 1: Using xml in a data set (ADO.NET)

Using XML in a DataSet (ADO.NET)

Ringo Ray H Piedraverde(Jr. Programmer)

Page 2: Using xml in a data set (ADO.NET)

Topics

• Writing DataSet Contents as XML Data (ADO.NET)

• Loading a DataSet from XML (ADO.NET)

Page 3: Using xml in a data set (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.

Page 4: Using xml in a data set (ADO.NET)

Code Snippet

Dim mds As DataSet = mds.tables(“tblUser”)

mUserDS.WriteXml(“User.xml", XmlWriteMode.WriteSchema)

Page 5: Using xml in a data set (ADO.NET)

Xml output

Page 6: Using xml in a data set (ADO.NET)

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.

Page 7: Using xml in a data set (ADO.NET)

Code snippet

Dim m_Ds as Dataset

Public sub ReadXML()

m_User.ReadXml(“User.xml", XmlReadMode.ReadSchema)

End Sub

Page 8: Using xml in a data set (ADO.NET)

Reading Output

Page 9: Using xml in a data set (ADO.NET)

• End