Error message "non-generic method" using ObjectDataSource and GridView

Here is my process: (all with visual web developer 2005 Express, April version.)

1. create new dataset in the app_code folder, called interaction.xsd. (right-click on the app_code directory and select new...)

a. Step through the TableAdapter Configuration Wizard.
b. Select the data connection (ManagementConnection String (Web.config)
c. Create new stored procedures
d. sql statement "SELECT Interaction.* FROM Interaction
e. new stored procedure names: InteractionSelect_sp, InteractionInsert_sp, InteractionUpdate_sp, InteractionDelete_sp
f. Fill method: FillInteraction, Get method: GetInteraction
g. Checked Create methods to send updates directly...
h. I now have Interaction.xsd.

2. Create new content page (code in separate file (Visual Basic) and uses master page), called Interaction.aspx.

3. In Design view, drag an ObjectDataSource onto the page.

a. (Configure Data Source) Selected InteractionTableAdapters.InteractionSelect_spTableAdapter.
b. Select method: GetInteraction(), return...
c. Update method: Update(Nullable<INT32> iFirmID, ... (Each field in the Interaction table is listed, as well as "Original_iInteractionID, Int32".)
d. Insert method: Insert(Nullable(int32> iFirmID,...(again, each field in the Interaction table is listed.)
e. Delete method: Delete(Int32 Original_iTransactionID), returns Int32

4. Drag a Gridview object onto the page.

a. Choose Data Source - ObjectDataSource1 selected.
b. Select "Enable Editing" and "Enable Deleting" also for the Gridview.

5. ctl-F5, select the page from the page navigation. Data is pulled from the database and is correct. Click on the Edit link, click on the Update link.

6. Get the non-generic method error.

Server Error in '/IntraVis' Application.


ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'Update' that has parameters: iFirmID, iContactID, vcType, vcSubType, vcContent, vcCmtRmk, vcAddInfo, rTimeSpent, dtDTGEntered, vcUserNameEntered, original_iInteractionID.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.InvalidOperationException: ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'Update' that has parameters: iFirmID, iContactID, vcType, vcSubType, vcContent, vcCmtRmk, vcAddInfo, rTimeSpent, dtDTGEntered, vcUserNameEntered, original_iInteractionID.

What am I doing wrong? What step am I missing?

chuck

[2975 byte] By [crbeckman] at [2007-12-16]
# 1
By default, the DataSet designer generates and Update stored procedures that allow editing of the primary key, so the signature of InteractionUpdate_sp will look like this:

InteractionUpdate_sp (iInteractionID, iFirmID, iContactID, vcType, vcSubType, vcContent, vcCmtRmk, vcAddInfo, rTimeSpent, dtDTGEntered, vcUserNameEntered, original_iInteractionID)

The GridView, on the other hand, assumes that the primary key is read-only, so it doesn't pass a new value for the primary key field, and therefore ObjectDataSource looks for a sproc that doesn't have this parameter. To make your page work, you have two options:

1) If you want updateable primary keys, edit the GridView columns and set ReadOnly=false on the BoundField associated to the InteractionID field.

2) If you don't want updateable primary keys, edit the definition of the InteractionUpdate_sp sproc to remove this parameter and regenerate the TableAdapter from the new sproc definition.

Hope this helps,
Bradley
Web Platform and Tools Team

Bradley at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Installing and Registering Visual Studio 2005 Express Editions...
# 2

Once you set the ReadOnly attribute of the ID field to False, you then get a useful:

Value cannot be null.
Parameter name: XXX

Error...

twisterjosh at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Installing and Registering Visual Studio 2005 Express Editions...
# 3
How do you do this. I dont know where to set the ReadOnly attribute
Tremint at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Installing and Registering Visual Studio 2005 Express Editions...
# 4

Actually, just set the oldvaluesparameter.... on the ODS to {0} instead of original_{0}

That will fix it without all the other stuff discussed above.

Basically on the id field it's trying to set "Original_ID" instead of "ID" (this assumes your column is ID

SDS-Consulting at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Installing and Registering Visual Studio 2005 Express Editions...
# 5
that works.

Brilliant !

Thank you.

scokim at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Installing and Registering Visual Studio 2005 Express Editions...
# 6
I simply replaced the parameter name from what it was "ContractorID" to

"original_ContractorID" since that what it was looking for, though I'm

not sure how to change that request.

All I did was change the names and it worked.

The code generated looks for the name you entered in the proc,

don't change the proc, just change the name in the code since the CLR

has it's mind made up to look for what it wants, give it what it wants.

Hope this helps somebody, I have 6 hours into digging for a solution, found this link in a blog got it to work and added this post

BusyDragon at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Installing and Registering Visual Studio 2005 Express Editions...
# 7
Busy Dragon wrote:
I simply replaced the parameter name from what it was "ContractorID" to

"original_ContractorID" since that what it was looking for, though I'm

not sure how to change that request.

All I did was change the names and it worked.

The code generated looks for the name you entered in the proc,

don't change the proc, just change the name in the code since the CLR

has it's mind made up to look for what it wants, give it what it wants.

Hope this helps somebody, I have 6 hours into digging for a solution, found this link in a blog got it to work and added this post

UPDATE: Change this
OldValuesParameterFormatString="original_{0}"
to
OldValuesParameterFormatString="{0}"

BusyDragon at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Installing and Registering Visual Studio 2005 Express Editions...
# 8

sorry to inform that

UPDATE: Change this
OldValuesParameterFormatString="original_{0}"
to
OldValuesParameterFormatString="{0}"
did not work in my case.

ShirajulAlam at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Installing and Registering Visual Studio 2005 Express Editions...
# 9
Did you try to rename anything else or just that one thing? I had to change the parameter name and viola it worked. But I tried nearly 100 other things too in addition to scouring the Web for an answer. Maybe one of the other things I tried will help you. Maybe...
BusyDragon at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Installing and Registering Visual Studio 2005 Express Editions...
# 10

It did not work with me but what I did to make it work i have changed the paramaters of my function as in the exception .

so look at the exception detail

Exception Details: System.InvalidOperationException: ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'UpdateSupplierAddress' that has parameters: supplierID, Address, City, Country, original_SupplierID, CompanyName, Phone

Here is my old function with the error

Public Function UpdateSupplierAddress(ByVal supplierID As Integer, ByVal address As String, ByVal city As String, ByVal country As String) As Boolean

and here after the update

Public Function UpdateSupplierAddress(ByVal supplierID As Integer, ByVal address As String, ByVal city As String, ByVal country As String, ByVal original_supplierID As Integer, ByVal CompanyName As String, ByVal Phone As String) As Boolean

This sample code was taken from the following article

http://www.asp.net/learn/dataaccess/tutorial02vb.aspx?tabid=63

so if you download the sample and add a simple page with objectdatasource and a detailsview you will get that error so you must change the functions to include the original_code and other missing parameters .

Regards

Tareq1176 at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Installing and Registering Visual Studio 2005 Express Editions...
# 11

Busy Dragon wrote: UPDATE: Change this OldValuesParameterFormatString="original_{0}"
to OldValuesParameterFormatString="{0}"

Unfortunutely it didn't work for me.
I've found that the problem only happened if your Update/Delete methods were generated using "Optimistic Concurrency". In this case you need to create own Update method with parameters expected/specified in ObjectDataSource/UpdateParameters element.

Alternatively, if you are happy NOT to check for concurrency, you can re-generate your adaptor methods as described here.

MichaelFreidgeim at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Installing and Registering Visual Studio 2005 Express Editions...
# 12

This is my solution that work for me. Go to xsd File and find Parameters Element for the update command then comment out the primary key(let's say "ID") and delete ID=[@ID] in command Text Element.
Then it 's work.

By the way, the solution to make ID column "ReadOnly" property = False is also work for me to.

Hope it 's work for you too.

sace22 at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Installing and Registering Visual Studio 2005 Express Editions...

# 13
Had the same problem with a DAL, and a BLL on top of that. Way I got around it was to write my update function in the BLL to be something like this:

Public Function UpdatePhoto(ByVal LocationGrouping As String, ByVal Description As String, ByVal ImageTakenDate As DateTime, ByVal original_ImageID As Int64) As Boolean
Adapter.UpdateQuery(LocationGrouping, Description, ImageTakenDate, original_ImageID)
Return True
End Function

Then, it captures the original_ID as it's passed to the function.

I don't include the ID column in the Gridview, it's not even declared as a bound field. I do have it declared as a datakey however. Now, I only set up 3 parameters, being my 3 form parameters that I want to update comming from the Gridview.

And it's done. No fuss, no mess, no choppy looking hacks. This is what the BLL and DAL were designed to do. Problem is, I was trying to do part of it's job for it, hence the ID field appearing twice. Take a step back, accept the gridview ID parameter, and you're good to go.

Tyfud at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Installing and Registering Visual Studio 2005 Express Editions...
# 14
I had this problem also, in a nutshell here is what I did to resolve these problems:

-Removed the "original_" from the "original_{0}" OldValuesParameterFormatString property

This solved the original error, but then I started getting this error:
Value cannot be null.
Parameter name: Original_Item

I solved this new error by edited the XML produced by the dataset. I just went into the Update function code and change the "(WHERE ColumnID = :Original_ColumnID) " to (WHERE ColumnID = :ColumnID) and then deleted the "Original_ColumnID" from the object datasource parameters.

Basically, unless for some strange reason you need to update the column ID, you can just change the Update function produced by the dataset to use the current column id in the WHERE clause.

Hope this helps...

JackBurton at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Installing and Registering Visual Studio 2005 Express Editions...