17 How to use Object Data sources Pages
![17. How to use Object Data sources Pages [560 -579] By, Mahammad Parvez Salim 17. How to use Object Data sources Pages [560 -579] By, Mahammad Parvez Salim](https://slidetodoc.com/presentation_image_h2/39232cab105defd4fc2b2aaa446dbb64/image-1.jpg)
17. How to use Object Data sources Pages [560 -579] By, Mahammad Parvez Salim Presentation ID-30

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 .






The aspx file • Object data source is implemented by object data controls which lets u use data binding with 3 layer architecture for database application. • The code for Default. aspx page for product list application using object data source is same as code for dropdown list and datalist control using SQL data source.

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

Thank You
- Slides: 18