
192
|
Chapter 6, Speed Hacks
#49 Generate Strongly Typed DataSets
HACK
Then you can read these values from the configuration file using the follow-
ing code anywhere in your application:
DatabaseSettingsConfig config = (DatabaseSettingsConfig)
System.Configuration.ConfigurationSettings.GetConfig(
"DatabaseSettings");
MessageBox.Show(config.Server);
The first line of this code gets an instance of the DatabaseSettingsConfig
class from the configuration file. You can then access any of the configura-
tion settings by simply accessing the properties of this class. In this example,
the value of the server element is shown to the user through a message box.
This custom tool is a great time-saver and makes it extremely easy to create
and use custom configuration sections.
HACK
#49
Generate Strongly Typed DataSets Hack #49
Make DataSets a little smarter by using Visual Studio and the XSD tool to
generate typed DataSets.
ADO .NET’s DataSet objects provide powerful functionality when working
with data. They allow you to easily scroll, filter, search, and sort data, as
well as work with hierarchical data and its relationships. However, your typ-
ical DataSet object is untyped, meaning it doesn’t really know and under-
stand what it is storing. It’s just a smart container for your data. You can
make a DataSet object even smarter by turning it into a strongly typed
DataSet object.
When working with an untyped DataSet, ...