I have a gridview (CustomerDetails) with editing enabled. When i click the edit button and update one of the 5/6 fields (i changed all fields to templatefield and then set the edittemplate to a label for the fields i didnt want to be editable) i get an error:
“ObjectDataSource ‘ObjectDataSource1’ could not find a non-generic method ‘UpdateCustomerAddressZip’ that has parameters: CustomerID, CustomerAddressOne, CustomerAddressTwo, CustomerZip, original_CustomerID”
The object datasource code is
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" InsertMethod="InsertCustomer"
OldValuesParameterFormatString="original_{0}" SelectMethod="CustomerDetails" UpdateMethod="UpdateCustomerAddressZip"
TypeName="Enterprise.CustomerEntityLayer">
<InsertParameters>
<asp:Parameter Name="CustomerID" Type="Int32" />
<asp:Parameter Name="CustomerAddressOne" Type="String" />
<asp:Parameter Name="CustomerAddressTwo" Type="String" />
<asp:Parameter Name="CustomerZip" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="CustomerID" Type="Int32" />
<asp:Parameter Name="CustomerAddressOne" Type="String" />
<asp:Parameter Name="CustomerZip" Type="String" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="Gridview1" DbType="Int32" Name="CustomerID" PropertyName="SelectedValue" />
</SelectParameters>
</asp:ObjectDataSource>
And my method in the entity layer is:
Public Function UpdateCustomerAddressZip(ByVal CustomerID As Integer, ByVal CustomerAddressOne As String, ByVal CustomerZip As Integer)
Dim dt As New CustomerDataTable
Dim C_row As CustomerRow = dt.NewCustomerRow
C_row.CustomerID = CustomerID
C_row.CustomerAddressOne = CustomerAddressOne
C_row.CustomerZip = CustomerZip
Adapter.UpdateCustAddZip(CustomerID, CustomerAddressOne, CustomerZip)
End Function
With the SQL being
UPDATE Customer
SET CustomerAddressOne = @CustomerAddressOne,
CustomerZip = @CustomerZip
WHERE CustomerID=@CustomerID
Can anyone advise where im going wrong?
Thanks
Simple answer:
change OldValuesParameterFormatString=”original_{0}”
to OldValuesParameterFormatString=”{0}”
As you can see from the error:
there’s an additional parameter: original_CustomerID
That is there in case you want to implement Optimistic Concurrency, to ensure that the Update you are performing on the database don’t conflicts with someone else changes.
It is beautifully explained in this tutorial by Scott Mitchell.
I report the relevant part here for convenience:
BUT, it is also related to the SqlDataSource.ConflictDetection Property
As stated there only when ConflictDetection is set to CompareAllValues the additional parameters should be added to the Update Method call (And the exact name of the parameters for the original values depends on the OldValuesParameterFormatString property.)
So this is not entirely clear to me… It seems that if, as it is by default, the ConflictDetection Property is set to OverwriteChanges, no additional *original_{0}* parameters should be added to the UpdateMethod!