Welcome Guest!
Create Account | Login
Locator+ Code:

Search:
FTPOnline
Channels Conferences Resources Hot Topics Partner Sites Magazines About FTP RSS 2.0 Feed

Free Trial Issue of Visual Studio Magazine

email article
printer friendly


Use DataSet to Store Application Settings
by Roman Rehak

January 2003 Issue

Technology Toolbox: C#, XML, ADO.NET

ADVERTISEMENT

Writing software applications often involves storing and retrieving application settings, such as saved options, user preferences, and the application's state when the user closes it. You can save these settings to the Registry, binary files, text files, or XML files. ADO.NET provides you with yet another technique for storing and retrieving application settings: You can use the DataSet object to hold them and persist them into a file easily.

You normally use datasets to hold results of database queries, but you can also create them on the fly and populate them programmatically. The DataSet object has characteristics that make it suitable for persisting application settings: It can hold hierarchical data in the Tables collection, and you can use the WriteXml() method to save the entire dataset into an XML file with a simple call:

ds.WriteXml(strFileName, 
   XmlWriteMode.WriteSchema);

Saving the schema with the data guarantees that the structure will remain the same when you reload the DataSet object. Use the ReadXml() method to load the persisted dataset from a file:

ds.ReadXml(strFileName);

You can use either the relational object model (DataTable, DataRow, DataColumn) or the XML object model to manipulate the data in the dataset, depending on which one you're more comfortable using. You can pass the DataSet object to an XmlDataDocument object's constructor to use the XML.NET API:

XmlDataDocument xmlDD = new 
   XmlDataDocument(AnyDataSet);


Back to top














Java Pro | Visual Studio Magazine | Windows Server System Magazine
.NET Magazine | Enterprise Architect | XML & Web Services Magazine
VSLive! | Thunder Lizard Events | Discussions | Newsletters | FTP Home