ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'Update' that has parameters:...

When building an editable ASP.NET 2.0 GridView or **DetailsView **this error is probably the most common issue. There must hardly be a developer who has not come across it at one time or another. It occurs when working with an ObjectDataSource based on a TableAdapter in ASP.NET 2.0, the easy path to enable Updating, Inserting and Deleting without any code or stored procedures the TableAdapter respresenting the data layer. This is the main advantage the GridView has over the DataGrid of .NET v.1x yore.

There is plenty of discussion of this issue available online, but two measure are mandatory:

First, always set the** ReadOnly** property of the data key fields of your GridView or DetailsView to** False**. It' True by default. It's very easy to forget to redo this when rebinding the GridView.

Second, when configuring the TableAdapter with th TableAdapter Configuration Wizard, be sure to not use a wildcard in the query at "What data should be loaded into the table?", so use

SELECT FirstName, LastName, ID FROM Customer;

instead of

SELECT * FROM Customer

A click on the Query Builder... button will reformat the query automatically.

Some say that disabling the second or third of the Advanced Options helps with this issue, however, I cannot confirm that is has any real effect.

Always remember to do and redo these two things and your GridView will manage your data just fine.

Posted: 15 November 2006

comments powered by Disqus