The SqlDataSource, on the other hand, requires a complete connection string. The AccessDataSource control needs just the file path to the Access database file. The sole difference between the AccessDataSource and SqlDataSource controls is how the database connection information is specified. This includes any OleDb- or ODBC-compliant data stores, such as Microsoft SQL Server, Microsoft Access, Oracle, Informix, MySQL, and PostgreSQL, among many others. While the AccessDataSource is designed to work specifically with Microsoft Access, the SqlDataSource control works with any relational database that can be accessed through. These two different controls lead many developers new to ASP.NET 2.0 to suspect that the AccessDataSource control is designed to work exclusively with Microsoft Access with the SqlDataSource control designed to work exclusively with Microsoft SQL Server. In addition to the SqlDataSource control, ASP.NET 2.0 also includes an AccessDataSource control.
The SqlDataSource and AccessDataSource Controls In the Inserting, Updating, and Deleting Data with the SqlDataSource Control tutorial, we'll see how to configure the SqlDataSource to support inserting, updating, and deleting. In this tutorial we'll focus on retrieving data from the database. As the following diagram illustrates, the these methods do the grunt work of connecting to a database, issuing a query, and returning the results.įigure 2: The SqlDataSource Serves as a Proxy to the Database The SqlDataSource s Select(), Insert(), Update(), and Delete() methods, when invoked, connect to the specified database and issue the appropriate SQL query. With the SqlDataSource, we must specify the database connection string and the ad-hoc SQL queries or stored procedures to execute to insert, update, delete, and retrieve data. The SqlDataSource provides the same functionality, but operates against a relational database rather than an object library. Once the ObjectDataSource s properties have been configured, a data Web control such as a GridView, DetailsView, or DataList can be bound to the control, using the ObjectDataSource s Select(), Insert(), Delete(), and Update() methods to interact with the underlying architecture. As discussed in the Displaying Data With the ObjectDataSource tutorial, the ObjectDataSource has properties that indicate the object type that provides the data and the methods to invoke to select, insert, update, and delete data from the underlying object type. In this tutorial and the next three, we'll examine how to work with the SqlDataSource control, exploring how to query and filter database data, as well as how to use the SqlDataSource to insert, update, and delete data.įigure 1: ASP.NET 2.0 Includes Five Built-In Data Source Controls Comparing the ObjectDataSource and SqlDataSourceĬonceptually, both the ObjectDataSource and SqlDataSource controls are simply proxies to data.
The SqlDataSource can be used to access and modify data directly from a relational database, including Microsoft SQL Server, Microsoft Access, Oracle, MySQL, and others. Developing a robust architecture, however, may be unnecessary when creating exceedingly simple, one-off applications.ĪSP.NET 2.0 provides five built-in data source controls SqlDataSource, AccessDataSource, ObjectDataSource, XmlDataSource, and SiteMapDataSource. For sufficiently large or complex applications, designing, implementing, and using a tiered architecture is vitally important for the success, updatability, and maintainability of the application. Doing so places the specific database queries and business logic directly in the web page. While all of the tutorials so far have used the architecture to work with data, it is also possible to access, insert, update, and delete database data directly from an ASP.NET page, bypassing the architecture. Starting with the Displaying Data With the ObjectDataSource tutorial, we saw how to use ASP.NET 2.0 s new ObjectDataSource control to declaratively interface with the architecture from the presentation layer. The Data Access Layer (DAL) was crafted in the first tutorial ( Creating a Data Access Layer) and the Business Logic Layer in the second ( Creating a Business Logic Layer). IntroductionĪll of the tutorials we ve examined so far have used a tiered architecture consisting of presentation, Business Logic, and Data Access layers. Starting with this tutorial, we learn how the SqlDataSource control can be used for simple applications that do not require such a strict separation of presentation and data access. In the preceding tutorials we used the ObjectDataSource control to fully separate the presentation layer from the Data Access layer.