views:

237

answers:

2

Here's the setup

  • I have a DetailsView whose DataSource is an ObjectDataSource.
  • The ObjectDataSource has two methods, select and update, that are stored procedures defined in a TableAdapter.
  • The Select stored procedure takes 1 parameter--the record id--and returns the fields populated in the DetailsView.
  • The Update stored procedure takes three parameters--the record id, and two data fields.

The select process works fine.

However, when the I submit the update, I get the following error:

ObjectDataSource could not find a non-generic method Update that has parameters: [all 21 table columns]

I am trying to only pass the (3) necessary fields to the Update stored procedure, but the DetailsView is apparently trying to update using all of the fields it received from Select.

I know that I can access the NewValues collection from DetailsViewUpdateEventArgs, but I don't see a way to remove any of the parameters so that they match the definition in the stored procedure, the TableAdapter, and the ObjectDataSource.

Any ideas?

A: 

Perhaps this tutorial can provide some insight. As long as you specify your update method and update parameters in your datasource, this should work fine.

Aaron
Okay, we're headed in the right direction. In the tutorial that Aaron linked to, I found this:"To ensure that the ObjectDataSource invokes the [correct] UpdateProduct overload...we need to restrict the GridView to having editable fields for just the ProductName and UnitPrice. This can be accomplished by removing the other BoundFields and CheckBoxFields, by setting those other fields' ReadOnly property to true, or by some combination of the two."
dneaster3
Now the problem is that all of the fields in my DetailsView are TemplateFields, and they have no ReadOnly property. Just removing the EditItemTemplate has not worked, and I cannot, in this case, remove the fields entirely during DetailsViewMode.Edit. So while I have a greater understanding of the process, I still have not convinced .NET to use the correct update method.
dneaster3
A: 

I've been able to work around the problem for now by simply removing the unneeded values from the NewValues collection in the DetailsViewUpdateEventArgs. However, this is not optimal, since I've added another point of failure if there are changes to the stored procedure or the form.

I'd still like to know if a TemplateField can be set to ReadOnly the way that a BoundField can (see comments below Aaron's answer).

dneaster3