Search This Blog

Tuesday, October 11, 2005


ObjectDataSource is a cool feature of ASP.NET 2.0. It allows the abstraction of of the data access tier in a multi-tier approach. Data-bound controls can connect to the objectdatasource just like any other datasource. As the object data source is meant to hide the data layer from the presentation tier, you will not find CommandType properties such as the DeleteCommandType or the SelectCommandType. This helps in true abstraction of the data layer from the presentation layer.

Having said all good about ObjectDataSource, it is time disclose a fact. The ObjectDataSource cannot use methods that accept an "Object" as a parameter to Update, Delete or Insert. See the picture below

In the picture, you can see that the Update method is configured to UpdatePerson(Person person). However the runtime will error out with the following message.

"ObjectDataSource 'PersonDataSource' could not find a non-generic method 'UpdatePerson' that has parameters: FirstName, LastName. "

The cheat to this is to write a wrapper method around the UpdatePerson to accept individual attributes and use it. See code snippet below.

Public void UpdatePerson(string FirstName,string LastName)
Person p = PersonDAL.GetByName("John");
p.FirstName = FirstName;
p.LastName = LastName;


No comments: