Thursday night, I had the pleasure of presenting to the Hampton Roads SQL Server User Group. During my talk I showed how you can use the new ObjectDataSource control in ASP.NET 2.0, specifically, how you can add a new DataSet object to the App_Code folder, and the IDE will invoke a wizard which will help you configure the DataSet to use a DataTableAdapter that configures the DataSet to act as the source for the ObjectDataSource, thus giving you a layer of abstraction between your back-end database and your UI.
While my demo worked great from the read standpoint, I ran into an issue with updates, namely that I got an error similar to: "ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'Update' that has the parameters...", etc.
After a little looking around, it turns out that the cause of this error is a slight mismatch between the GridView control (which I was using for my databinding) and the DataTableAdapter. The GridView control assumes that a Primary key column should be read-only (which typically, they are), and so does not pass the PK column when invoking the Update statement specified in the ObjectDataSource. By default, the DataTableAdapter's Update Method includes the all columns from the Select query from which it is generated.
There are two ways you can fix this mismatch:
Thanks to everyone who came out to the meeting.
So I’m writing a quick demo for a book chapter, and I want to use something close to best practices,