Some workaround for ObjectDataSource: could not find a non-generic method '...'

I tried to use generated by VS 2005 typed dataset/adaptors with  ObjectDataSource and got am error:

Exception Details: System.InvalidOperationException: ObjectDataSource 'odsCascadeRulesValues' could not find a non-generic method 'Update' that has parameters: ....


I found the thread that suggested some workarounds, but the simple one “Change this  OldValuesParameterFormatString="original_{0}" to  OldValuesParameterFormatString="{0}" 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:
1.Select Adaptor
2.Click Configure
3.Click "Advanced Options..." 
4.Untick  "Use Optimistic Concurrency".
5.Click "Finish" to generate Updates

Now you should go to your ASPX/ASCX and configure ObjectDataSource . Ensure that correct Update and Delete methods are selected.

There is another thread “Dataset + ObjectDatasource + GridView + ASP.NET 2” that discuss different options for workaround.
Update: I've posted related “Editable GridView with ObjectDatasource and Update method parameters.” and "Why we are getting ObjectDataSource: could not find a non-generic method 'Update'" .

 

posted @ Wednesday, August 30, 2006 3:16 PM
Print

Comments on this entry:

# Some workaround for ObjectDataSource: could not find a non-generic method '...'

Left by Just Coding at 9/7/2006 1:04 PM
Gravatar
Today I was playing with the new DataBind capabilities of ASP.Net 2.0, and found this error.....

# A fix for a similar problem...with a "why"

Left by codequest at 9/9/2006 9:20 AM
Gravatar

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'

Left by Noli San Jose at 9/12/2006 2:08 PM
Gravatar
The alternative ("1.Select Adaptor
2.Click Configure..."), I think, does not apply if you are working with Stored Procedures as the data source and not a dynamic SQL, since the "Advanced Options..." is not available.

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'

Left by Pablo at 11/11/2006 2:06 AM
Gravatar
This is the real solution.

I googled the error and I searched on this posts. I found several "solutions", but none of them worked for me. After deleting the OldValuesParameterFormatString property, I ended up with exactly the same fields in the error description and in the dal definition. Incredible: the columns were exactly the same and still I got the error!! There was no one-more or on-less column, the count was the same, the names were the same.

Open your DAL definition (XSD file), select your update method (the one shown on the error description), and in the properties windows click on the Parameters (Collection) button, this brings up a new small window, just select your id parameter and remove the "Original_" thing in "ParameterName", and set "SourceVersion" to "current".

For me, the ParameterName was showing "Original_id" or something like that, I set it to just "id", which is the name of my primary key.

SourceVersion was showing "Original", when all the other columns show "Current", so I changed it to "Current".

I saved everything and tried to update the record, and it was updated correctly. I am using a gridview and objectdatasource.

I hope this helps someone!!

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'

Left by Byron at 1/8/2007 3:53 AM
Gravatar
This error is about to cause me to jump out of a window!!! It should not be this freaking hard!

Now, after changing variable names between my BLL and DAL 40-11 times, I finally got the non-generic error to go away, but now it just doesn't update.

Just venting...Is this a Microsoft problem, or is it me?!?!

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'

Left by Michael Freidgeim at 1/8/2007 7:55 AM
Gravatar
It is a Microsoft Problem(see weblogs.asp.net/bradygaster/archive/2006/09/26/How-to-Bloody-Your-Forehead.aspx), but MS support answered (see connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=111156), that is by design(bad design!)

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'

Left by Khurram at 1/9/2007 9:47 PM
Gravatar
I tried all the possible that I could. Even in the article by scott
http://www.asp.net/learn/dataaccess/tutorial16vb.aspx?tabid=63&bcsi_scan_B89A47EC81851AF1=fY4zDP7Eq2KBZrAcOuouLwIAAADc5iMA&bcsi_scan_filename=tutorial16vb.aspx

he talked about avoiding this problem by removing the OldValuesParameterFormatString property or setting it to {0}. But in any case it passes the original parameters as well.

What a shame that things are made so complicated for nothing. I had to manually override the handlers to make it work. Now after wasting so much time I am asking myself was it worth trying? In any case problem can be avoided by overriding the handlers like

protected void gvOutsiders_RowEditing(object sender, GridViewUpdateEventArgs e)
{
//odsOut is the object datasource while gvOutSiders it the gridview
odsOut.UpdateParameters.Clear();
odsOut.UpdateParameters.Add("company", e.NewValues[0].ToString());
odsOut.UpdateParameters.Add("outsiders", e.NewValues[1].ToString());
odsOut.UpdateParameters.Add("outID", e.Keys["out_id"].ToString());
odsOut.Update();
gvOutSiders.EditIndex = -1;
e.Cancel = true;

}

Regards,
Khurram

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'

Left by Khurram at 1/9/2007 9:51 PM
Gravatar
Just to precise that its called by setting the OnRowUpdating of the gridview.

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'

Left by Paul Pleasant at 2/3/2007 4:53 AM
Gravatar
1. Change the WHERE clause for the update to : "WHERE (ID = @ID)" substituting "ID" with the name of your primary key column.
2. Regenerate the template control (FormView, GridView, etc) This must be done or you must manually correct the markup.
3. Change: OldValuesParameterFormatString="original_{0}" to OldValuesParameterFormatString="{0}"

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'

Left by Jean-Luc ROBERT at 2/27/2007 10:05 PM
Gravatar
After hours spent on this problem, i've found this solution: in the DataSet object (xsd file), go in the property grid from the tableAdapter and set "GenerateDBDirectMethods" to true, this property is disabled in the wizard, i don't know why.

Then the new update method is available in the ObjectDataSource, just set the OldValuesParameterFormatString="{0}"

Then set the following gridview properties :
- DataKeyNames to set the primary key names
- Not updatable columns to "readonly"

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'

Left by Hoopes at 3/14/2007 12:57 AM
Gravatar
The problem I had was that the table I was updating had a primary key. By default VS2K5 will make the field that is the primary readonly. Changing it to readonly=false solves the problem but creates a new one however I changed the field to a template field. Once converted to a template field I then when to the Edit Template feature and made the textbox readonly from there.


HTH

# Why we are getting ObjectDataSource: could not find a non-generic method 'Update'.

Left by Michael Freidgeim at 7/18/2007 1:23 AM
Gravatar
Posted by Microsoft on 5/05/2007: "We have fixed the issue with an additional update function.
The fix will be available in the next VS release." https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=260674

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'

Left by morne at 1/24/2008 9:34 PM
Gravatar
Dude u r a god among men,i almost swore off visual studio all together!good job it works like a charm!!!!
happy programming people....

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'

Left by Chidozie Bright at 8/2/2008 2:36 PM
Gravatar
My solution for this was to add a OBJECTNAME.PARAMETER.Clear(); prior to adding my .Add

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'

Left by TheRage3K at 9/2/2008 8:26 PM
Gravatar
Wow, this sure was fun. Not wanting to play with an XSD generated by MS (could be overwritten if I farted at it the wrong way). I stumbled across something veddy curious... I found if my DataKeyNames was set to the primary key and if my column names in SQL matched the parameter names of my update method (same goes for primary key column), and my primary key field was set to ReadOnly, this thing magically works.

So if my updated method was Update(Guid RowID, string TacoBell, bool isFourthMeal), and my database fields were row_id, taco_bell and is_fourth_meal, then my SQL to populate the gridview via an ObjectDataSource had to be SELECT row_id AS RowID, taco_bell AS TacoBell, is_fourth_meal AS IsFourthMeal.

As long as everything matches (SQL statement matches the GridView data fields/binding expressions, and those match the Update Parameter names in the ObjectDataSource, then I was good to go (plus Read-Only PK, and DataKeyNames = PK).

I am using .NET 2.0, C#, VS 2005 SP1

Happy Coding!

TheRage3K

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'

Left by Chris at 10/16/2009 7:44 PM
Gravatar
Hi Khurram. Yours worked for me. I was using asp.net 3.5, along with gridview, objectdatasource, and lists, and my own custom objects to retrieve/update/insert/delete data. Thank you! Even for VS 2008, MS has NOT got the wizard to actually work yet! Shame on you MS.

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'

Left by Regina at 1/20/2010 5:33 PM
Gravatar
Ok I think I have tried it all. I have taken the Original out of Old Values... I have taken OldValuesParameterFormatString="{0}" completly out of my datasourse. I have taken the Original out of my field @AutoID in the stored procedure for update. But cannot get the insert to work using BLL in a form view. I am ready to give up. It works great if I bypass the BLL and use the Stored procedure directly for the Datasource. The AutoID is included in my Table Adapter, It is not included in my insert control in the BLL. Should it be? From everywher I have looked it is not included. HELP!!!!

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'

Left by Logan at 3/3/2010 4:58 AM
Gravatar
I got this error, but when I checked the TableAdapter's Advanced Properties, I found that "Use Optimistic Concurrency" was already deselected.

I scrapped the whole thing and instead opted for calling an sp via SqlCommand

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'

Left by Andres at 11/28/2011 10:00 AM
Gravatar
los parametros deben ser iguales a los campos en la base de datos y las llaves no pueden ser editables

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'

Left by Hamideh at 3/6/2012 1:12 AM
Gravatar
I was so much near the the point to give up too,but i finally found this useful tutorial by MSDN itself,saying that the whole problem is because the "DataKeyNames" property of the GridView may not be set correctly .Meaning ,The values that are assigned to the Delete(or Update)Parameters should be the values of the DataKeyNames field(s) for the row that we are trying to update or delete.
Hope this helps.

Your comment:



(not displayed)

 
 
 
 
 

Live Comment Preview:

 
«August»
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456