Data Sources for Web Forms Pages
The Web Forms page architecture provides a very flexible notion of data. This includes everything from traditional database access, to using XML documents as a data source, to generating data at run time and storing it in an array.
To read and write database data, you use ADO.NET. ADO.NET includes managed data providers (connection and command objects) to communicate with SQL Server or OLE DB-compatible databases. ADO.NET also includes support for disconnected data access via a dataset, which is an in-memory cache into which you can read records to work with. For details, see Introduction to Datasets.
Note You need to be sure that when your application runs, it has sufficient permissions to establish a data connection to your data source. For details, see Access Permissions for Web Applications.
Alternatively, you can use ADO.NET objects to execute SQL commands or stored procedures directly. This allows you to read data straight from the database and send updates back. For details, see Introduction to DataCommand Objects in Visual Studio.
Another possible source of data in a Web Forms page is an XML document or stream. You can work with XML data in two ways:
- If the XML data is structured — that is, if it can be represented as relational data (even if it is not stored that way) — then you can convert the XML data into a dataset and use ADO.NET data functions to read and update the data. This allows you to take advantage of the comparatively sophisticated and simple data-processing functionality of datasets. You can then convert the data back to XML to share with other processes. For details, see Synchronizing a DataSet with an XmlDataDocument.
- If the XML data cannot be represented as relational data, you can use XML parsing and processing functions from the System.Xml namespace to manipulate the data. In Web Forms pages, you can do this using the XML Web Server Control. Alternatively, you can work directly with XML documents in code. For details, see Employing XML in the .NET Framework.
Note You need to be sure that when your application runs, it has sufficient permissions to read (and if necessary, write to) XML files. For details, see Access Permissions for Web Applications.
Other Data Sources
Web Forms pages allow you to work with virtually any other type of data as well. The data-binding architecture of Web Forms pages allows you to bind a control to any structure. In practice, this means you can bind to any arrays or collections available in the page, as well as to properties of the page or of other controls.
For ultimate flexibility, you can perform data binding at run time. Each control, as well as the page itself, supports a data-binding event. By writing handlers for this event, you can bind controls on the page to any data you fetch or calculate during page processing.
For details, see Data Binding Single-Value Web Server Controls at Design Time.