How to Use Ent.Lib.2.0 with ObjectDataSource

Topics: Data Access Application Block
Jan 20, 2007 at 10:17 AM
Hi to all,
i hv downloaded the Ent.Lib Jan 2006
i am getting problem in using (selecting,inserting,updatin,deleting) the data block with ObjectDataSource, it always give "non-generic" error, i tried so many ways but each time i get different errors.

details of implementation
i generated a class for my table "University"
in which all the properties name are same as table's fields name

a dbhelper file which has a common connection string, which i used in all functions like

Public Function ExecuteNonQuery(ByVal storedProcedureName As String, ByVal ParamArray parameterValues As Object()) As Integer
Return con.ExecuteNonQuery(storedProcedureName, parameterValues)
End Function

now i call this function in objectDataSource's update method
when the update link is clicked in detailsview i put all the values from textboxes to the University class property like

Dim prm as university = new university()
Dim txtName As TextBox = DetailsView1.FindControl("txtName")
prm.Name = txtName.Text
and so on...
then pass the university property to the objectDataSource's parameters like
e.InputParameters("storedProcedureName") = "UniversityUpdate"
e.InputParameters("parameterValues") = prm.Name,prm.Id, and so on...

but its not working and i am not getting any tutorial to use Data Access Application Block 2.0 with ObjectDataSource Control so i found this place, if any body has time to help me then it will be very great help because i think this one is the first help on using library with objectDataSource.
Thanks to all for reading this
Jan 22, 2007 at 3:12 PM
As you know, an ObjectDataSource Control just binds to methods on a custom class to do selects, inserts, updates, and deletes. Usually this is a business layer class that delegates the actual data access operations to a data access layer class that uses the DAAB.

So, the ObjectDataSource Control will bind to say a Customers Class:

public class Customers
private ICustomerDataService _service;

public Customers()
_service = CustomerDataService.Create();

public DataSet GetCustomers()
return _service.GetCustomers();

The Customers Class delegates the work to an ICustomerDataService that uses the DAAB internally to work with the data store. Here is an example of an SqlCustomerDataService Class that implements ICustomerDataService:

public class SqlCustomerDataService : ICustomerDataService
private Database _database;

public SqlCustomerDataService(Database database)
_database = database;

#region ICustomerDataService Members

public DataSet GetCustomers()
return _database.ExecuteDataSet(CommandType.StoredProcedure, "GetCustomers");


If you are looking for more thorough examples, I recommend checking out the Web Client Software Factory for web-based clients:

Or the smart client software factory for winform-based clients:

I talk about the web client software factory a bit here:

Here is more on ASP.NET 2.0 and ObjectDataSource Control:




David Hayden
Microsoft MVP C#