Geeks With Blogs

Michael Freidgeim's Blog MS .Net Development

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 on Wednesday, August 30, 2006 3:16 PM ASP.NET | Back to top


Comments on this post: Some workaround for ObjectDataSource: could not find a non-generic method '...'

# Some workaround for ObjectDataSource: could not find a non-generic method '...'
Requesting Gravatar...
Today I was playing with the new DataBind capabilities of ASP.Net 2.0, and found this error.....
Left by Just Coding on Sep 07, 2006 1:04 PM

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

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'
Requesting 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.
Left by Noli San Jose on Sep 12, 2006 2:08 PM

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'
Requesting 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!!

Left by Pablo on Nov 11, 2006 2:06 AM

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'
Requesting 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?!?!
Left by Byron on Jan 08, 2007 3:53 AM

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'
Requesting 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!)
Left by Michael Freidgeim on Jan 08, 2007 7:55 AM

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'
Requesting 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
Left by Khurram on Jan 09, 2007 9:47 PM

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'
Requesting Gravatar...
Just to precise that its called by setting the OnRowUpdating of the gridview.

Left by Khurram on Jan 09, 2007 9:51 PM

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'
Requesting 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}"
Left by Paul Pleasant on Feb 03, 2007 4:53 AM

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'
Requesting 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"
Left by Jean-Luc ROBERT on Feb 27, 2007 10:05 PM

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'
Requesting 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
Left by Hoopes on Mar 14, 2007 12:57 AM

# Why we are getting ObjectDataSource: could not find a non-generic method 'Update'.
Requesting 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
Left by Michael Freidgeim on Jul 18, 2007 1:23 AM

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'
Requesting 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....
Left by morne on Jan 24, 2008 9:34 PM

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'
Requesting Gravatar...
My solution for this was to add a OBJECTNAME.PARAMETER.Clear(); prior to adding my .Add
Left by Chidozie Bright on Aug 02, 2008 2:36 PM

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'
Requesting 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
Left by TheRage3K on Sep 02, 2008 8:26 PM

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'
Requesting 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.
Left by Chris on Oct 16, 2009 7:44 PM

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'
Requesting 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!!!!
Left by Regina on Jan 20, 2010 5:33 PM

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'
Requesting 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
Left by Logan on Mar 03, 2010 4:58 AM

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'
Requesting Gravatar...
los parametros deben ser iguales a los campos en la base de datos y las llaves no pueden ser editables
Left by Andres on Nov 28, 2011 10:00 AM

# re: Some workaround for ObjectDataSource: could not find a non-generic method '...'
Requesting 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.
Left by Hamideh on Mar 06, 2012 1:12 AM

Your comment:
 (will show your gravatar)


Copyright © Michael Freidgeim | Powered by: GeeksWithBlogs.net | Join free