Technical Training
ASP.NET 2.0ASP.NET Data Source Object Model Page - 2
ASP.NET Data Source Object Model
The DataSetDataSource works with an XML data source object. It can be specified as a string or a filename. This control cannot be bound to a DataSet object. The methods of the class are used to retrieve the DataSet object and set schema information. Though it is XML based, it only supports tabular representation of data and can be bound only to list controls. These controls are used only in read only scenarios. However, the control supports editing of underlying XML data.
The ObjectDataSource supports custom binding. This class is specified using the TypeName property of a control. It allows developers to structure applications using three tier architecture and still take advantage of the ASP.NET 2.0 declarative data binding model. It follows specific design patterns and includes parameterless constructors and methods that behave in familiar ways.
The SqlDataSource is a connection to an ADO.NET data provider and returns a SQL data. It includes data sources accessible through OLE DB and ODBC. The connection string and provider name can be specified through properties of this class.
Hierarchical Data Source Controls
As the name suggests these controls allow the representation of data hierarchies. It derives from the abstract class HierarchicalDataSourceControl class which implements the IHierarchicalDataSource Interface. It has a single method called the GetHierarchicalView. This method retrieves hierarchical data source view and returns the object of the type after taking the path of the view. Each level of data is supported by a view. The ViewPath parameter indicated the path in the hierarchy for navigation and retrieval of the requested data. Though conceptually the same, tabular and hierarchical views, are different in so far as the data they handle are different. The SiteMapDataSource and the XmlDataSource are two hierarchical data source controls supported by ASP.NET 2.0.
The SiteMapDataSource control has a rich navigation infrastructure that allows developers to specify the site structure. The control is the SiteMapDataSource class and connects to an XML data source. A configuration file named app.sitemap created at the root of the application is referred to at runtime. It creates a relationship between the pages of the site. A control named NavigationPath is added to the pages and this control retrieves the site map and produces the necessary markup. We shall study this control in greater detail in the next lesson of this series. This class has a few properties that relate to the site map provider. SiteMapProvider specifies the name of the site map provider. The SiteMapViewtype describes the type of view that has to be generated by the control. The StartingNodeType, StartingNodeUrl and StartingDepth are properties that indicate the node with which to start, its address and the depth to which the hierarchy needs to be displayed.
The XmlDataSource control is a special control that supports both tabular and hierarchical views of data. The tabular version displays the data as a list of nodes at a specified level of hierarchy, while the hierarchical view shows the complete hierarchy. This control can accept XML input data as relative or an absolute filename assigned to the Datafile property or to a string containing the XML content assigned to the Data property. It can also be passed in as a SchemaFile or Schema string. The control exposes the data for the XML data source through the IDataSource or the IHierarchicalDataSource interface. It is normally bound to a hierarchical control such as TreeView. The class can also transform its data using Extensible StyleSheet language transformation(XSLT). The transform file can be set using the TransformFile property or assigning a string property named Transform. The TransformArgumentList property passes arguments to the style sheet using the XSL Transformation. Once the data is transformed the XmlDataSource property becomes read only.
The SqlDataSource Control: Usage
The SqlDataSource control defines a connection between the ADO.NET managed data provider –Sql Server, OLE DB, ODBC, Oracle or a third party provider. Commands to perform common data operations such as query or sort can be specified. The text assigned to InsertCommand or SelectCommand can be parsed to verify whether it is a valid SQL command that is compliant with the expected syntax of the corresponding statement. By default the command text is taken as the name of the stored procedure. The binding between the data provider and the user code takes place codelessly or declaratively. It can also be invoked programmatically. It incorporates a number of functions and features and can accept parameters in both stored procedures and in SQL Commands.
Data Source Parameters
The parameter collection is defined in the collection class name ParameterCollection. All objects whose base class is Parameter can be stored in this collection. Parameterized query, filter expressions, or commands executed by the data source control are examples of Parameter objects.
Parameters can be obtained and set in several ways. ControlParameter gets the parameter value from any public property of a server control. CookieParameter sets the parameter property of the cookie. FormParameter gets the parameter value from the specified input field in the HTTP request form. ProfileParameter gets the parameter value from the specified property name in the Profile object from the personalization scheme of the application. QueryStringParameter gets the parameter value from the specified variable in the request query string. SessionParameter sets the parameter value based on the content of the specified session slot. The Name property of the parameter class has a set of properties that specify the role and implementation of the property.
The Evaluate method of the Parameter class updates and returns the value of the parameter object. This method can be overridden by different parameter classes to make it return an appropriate value.
The binding of the parameters and the actual values in the parameter class depends on the method used by the provider to handle and recognize parameters. For instance if named parameters are supported the binding will occur if names of the placeholders match with the names of the parameters. Otherwise matching can be based on position. This is a typical scenario when OLE DB is used to access the data;
Caching is required for improving application performance and for data source controls. Data is retrieved and made available to other components within the application faster if caching is available. The SqlDataSource control can be instructed to cache data in the data source mode—DataSet. It provides for automatic caching of data using time based cache expiration policy or on the basis of the SqlCacheDependency expiration policy. To enable automatic caching the EnableCaching property has to be set to True and the CacheDuration property value should be set to a non zero value. An absolute expiration property is used by default but this can be configured by setting a value to the CacheExpirationPolicy property. SqlCacheDependency binds to a timestamp of the SQL Server table. It forms an expiration based on the dependency between the SQL server database and the contents of the control. The dependency is defined as a string property with the syntax “database:table”. Multiple table dependencies can be specified using colons. This feature can also be used to invalidate related values in the cache if the contents in the table changes. This is useful when an update can force a refresh on the page.
In this section of the tutorial we have examined in some detail the codeless way in ASP.NET 2.0 enables users to connect to data sources from a web application. In the next section we shall study the Data Source Wizard which makes this task even easier.
ASP.NET 2.0
- Getting started with ASP.NET 2.0
- .NET Framework Fundamentals
- Microsoft.NET Framework Tools
- Application Development in .NET
- What's New in the .NET Framework 2.0 ?
- Introduction to Visual Studio.NET
- Installing Visual Studio.NET 2005
- Working with Visual Studio.NET Web Applications
- Whats New in ASP.NET 2.0
- Creating an ASP.NET Application
- ASP.NET Code Directory
- ASP.NET Page Object Model
- ASP.NET Server Controls
- ASP.NET Working With Master Pages
- ASP.NET Creating Content for Master Page
- ASP.NET Referencing Master Page Members
- ASP.NET Changing Master Pages Dynamically
- ASP.NET Creating Nested Master Pages
- ASP.NET Working with Web Parts
- ASP.NET Using Web Parts and Controls in Web Pages
- ASP.NET Web Pages and Layout
- ASP.NET - Adding Web Parts at Run Time
- ASP.NET Personalization: User Profiles and Themes
- ASP.NET Data Access features
- ASP.NET State Management
- ASP.NET Customizing the Session State Mechanism
- ASP.NET State Management And Caching
- ASP.NET Security
- Forms Authentication in ASP.NET
- ASP.NET Managing Membership and Roles
- ASP.NET Configuring Page-Level Caching
- ASP.NET Setting Application-Level Caching
- ASP.NET Data Source Object Model
- ASP.NET SqlDataSource Control
- ASP.NET Data Bound Controls
- ASP.NET GridView Control
- ASP.NET GridView Filtering
- ASP.NET Adding Sorting and Paging in GridView
- ASP.NET DataBound Controls - Details View
- ASP.NET Using a Grid to Display Detail Information
- ASP.NET Displaying Master-Detail Data on the Same Page
- Displaying Master-Detail Data on Separate Pages in ASP.NET
- ASP.NET Creating Web Wizards
- ASP.NET : Dynamic Image control
- ASP.NET Advanced Site Functionality







