How to use Object Data sources with ADO
![How to use Object Data sources with ADO. NET(pages [551 -569]) By Naga Krishna How to use Object Data sources with ADO. NET(pages [551 -569]) By Naga Krishna](https://slidetodoc.com/presentation_image_h2/862a7bfcf2186598469dc79e9ab72051/image-1.jpg)
How to use Object Data sources with ADO. NET(pages [551 -569]) By Naga Krishna Ganta Presentation ID: 10

Outline • An introduction to Object. Data Sources • • How 3 -layer applications work in ASP. NET How to use Object. Data. Source control How to configure an Object. Datasource control How to work with bound controls • A Product List application • The aspx file • The product. DB class • How to create a data access class • How to design data access class • How to create a select method

How 3 -layer applications work in ASP. NET • An object data source is implemented by the Object. Data. Source control, lets you use data binding with the 3 -layer architecture for a database application. • An Object data source is similar to a SQL data source. However, instead of directly accessing a database, the object data source gets its data through a data class that handles the details of database access. • A 3 -layer architecture separates the presentation, business rules and Data access components of application. • The 3 -layers of architecture are: • Presentation Layer • Middle Layer • Database Layer


Presentation Layer • Consists of ASP. NET pages that manage the appearance of the application • Includes bound Data controls and Object. Data. Source objects that bind the data controls to the data. Middle Layer • Contains the data access classes that manage the data access for the application. • Contains business objects that represent business entities such as customers, products, or employees and that implement business rules such as credit and discount policies. Database layer • Consists of database that contains data for the application. • The SQL statements that do the database access should be saved in stored procedures within the database. • But SQL classes are often stored in the data access classes.

How to use Object. Data. Source control • The Object. Data. Source control specifies the name of the data access class and the methods used to select, update, delete and insert data .


How to configure an Object. Data. Source Control


Product. DB class • A class file is added to App_Code folder using add new item. • Two methods are created Get. All. Catergories and Get. Product. By. Category • Another method Get. Connection. String is created which is declared as private • Get. All. Catergories method starts by creating a connection to Halloween databases by calling Get. Connection. String method • Now this methods creates a string which contains the select statement that will retrieve the data from Halloween database • Finally the connection is opened Execute reader method of the command object is called and object that contains the requested data is returned to object data source


How to create a data access class • The most challenging aspect of object data source is developing data access class • Data access class have four different types of methods that are used to select, insert, update and delete data. • For example; Product. DB class uses select method • Data access method can be static or instance methods • The preferred is static method to select, insert, delete and update where ever possible.


How to create select method • Select statement returns data retrieved from databases • Data could be of any form dataset or datatable • If the select method returns datatable, the objectdatasource control automatically extracts a dataview from the table and uses view for data binding • If select method returns dataset, Object. Data. Source control extracts data view from first data tablein dataset and uses the view for data binding

- Slides: 15