XML data definition format is heavily used in nowadays applications since it is very rich data definition method. Working with XML data is very customizable, easy and reliable. Important features of XML language are;
Generate XML file from dataset
// Connect to database
OleDbConnection con = new OleDbConnection('');
// Create new dataset
DataSet ds = new DataSet();
// Create new data adapter
OleDbDataAdapter da = new OleDbDataAdapter();
// Create SQL command
OleDbCommand cmd = new OleDbCommand("SELECT * FROM tblMyData", con);
// Set SQL command to data adapter
da.SelectCommand = cmd;
// Fill dataset
da.Fill(ds);
// Write data from dataset to XML file called "YourXMLFile.xml"
ds.WriteXml("c://YourXMLFile.xml");
Read data from XML file and fill dataset
"WriteXML()" method is used to write XML data from dataset into physical file, memory stream or character stream. In same way you can use "ReadXML()" method to read data from XML file and assigned to dataset.
- well defined schema
- purely character based data definition method
- customizable tags
- easy validation of XML documents
Generate XML file from dataset
// Connect to database
OleDbConnection con = new OleDbConnection('
// Create new dataset
DataSet ds = new DataSet();
// Create new data adapter
OleDbDataAdapter da = new OleDbDataAdapter();
// Create SQL command
OleDbCommand cmd = new OleDbCommand("SELECT * FROM tblMyData", con);
// Set SQL command to data adapter
da.SelectCommand = cmd;
// Fill dataset
da.Fill(ds);
// Write data from dataset to XML file called "YourXMLFile.xml"
ds.WriteXml("c://YourXMLFile.xml");
Read data from XML file and fill dataset
"WriteXML()" method is used to write XML data from dataset into physical file, memory stream or character stream. In same way you can use "ReadXML()" method to read data from XML file and assigned to dataset.
Comments
Post a Comment