HOW TO USE OBJECT DATA SOURCE Name Bakul

HOW TO USE OBJECT DATA SOURCE Name: Bakul Ahluwalia Presentation ID: #11

Outline: � How to create update, delete and insert methods. � How to use attributes to mark a data access class. � A category maintenance application � How to use paging with Object data sources:

How to create, update, delete and insert methods: To properly design an update, delete or insert method, you must be aware of how the Object. Data. Source control generates the parameters passed to these methods. � How parameters are generated: � � When the insert or delete is called, one parameter of the business class type is generated and passed to the method. � One parameter of the business class type is also generated and passed to the update method when this method is called if optimistic concurrency isn’t used. � If optimistic concurrency is specified, two parameters are generated and passed to the update method. One contains the original value and the other contains the new values.

Requirements for the business class: �The class must provide a parameter less constructor. �The class must have public properties with names that match the names of the bound fields that are passed to the object data source from the bound control. �The public properties must have both get and set procedures.

How to use attributes to mark a data access class: You can use Data. Object and Data. Object. Method attributes to mark data access classes and methods. Visual studio uses these attributes to determine which classes and methods to list in the drop-down lists of the data source Configuration wizard. � The Data. Object and Data. Object Method attributes are stored in System. Component. Model namespace. �

Attributes for making data access classes:

A marked data access class:

A Category Maintenance application:

The version of the Category Maintenance application uses a Grid. View control to update and delete rows and a Details View control to insert rows. These controls are bound to an Object Data. Source control that accesses the Categories table of the halloween database. � The data access class named Category. DB provides the select, insert, update and delete methods. �

Methods of the Category. DB class:

Default. aspx file: Code for Grid. View

Default. aspx Code for Object. Data. Source with update, insert, delete parameters:

Code behind file: � This file consists of five event handlers that handle the exceptions that might be raised and the concurrency errors that might occur when the object data source’s update, delete or insert methods are called.

Default. aspx. cs file:

Category. DB class: � This class uses the Data. Object attribute to mark the class as a data. Object class and Data. Object. Method attribute to mark the methods as data. Object methods. � Four public methods in the class provide for Select, insert, delete and update operations perfomed by this application.

Category. DB. cs file:

Queries? ?

Thank You
- Slides: 18