Solved

ObjectDataSource UpdateMethod fails

Posted on 2009-05-04
9
646 Views
Last Modified: 2013-12-17
Greetings all

I am trying to update a table via the UpdateMethod of teh ObjectDataSource. I am getting this error: "ObjectDataSource 'spousalODS' could not find a non-generic method 'SpousalODS_Update' that has ........."

I have googled this but can not find a clear answer - soem feeling is that each and every field has to be specified. My data is coming froma formview which contaisn (currently) 52 fields. Do I have to type in each as a parmeter for the UpdateMethod?

In advance, thanks!!!

   allanmark
0
Comment
Question by:allanmark
  • 4
  • 4
9 Comments
 
LVL 8

Accepted Solution

by:
ppittle earned 250 total points
ID: 24296562
AllanMark,

Scott Mitchell has an excellent set of tutorials on ObjectDataSource available at: http://www.asp.net/learn/data-access/

This one should be perticularily relevant: http://www.asp.net/learn/data-access/tutorial-17-cs.aspx

As for a direct response to your error message, this is a quote from the above tutorial:

"Note that the ObjectDataSource's OldValuesParameterFormatString property is set to original_{0}. This property is set automatically by Visual Studio when using the Configure Data Source wizard. However, since our BLL [Business Logic Layer] methods don't expect the original ProductID value to be passed in, remove this property assignment altogether from the ObjectDataSource's declarative syntax.

Note: If you simply clear out the OldValuesParameterFormatString property value from the Properties window in the Design view, the property will still exist in the declarative syntax, but will be set to an empty string. Either remove the property altogether from the declarative syntax or, from the Properties window, set the value to the default, {0}."

By defualt, the ODS is configured to work with the TypedDataSets Optomistic Concurency features, so if you have an update method with say 10 parameters, the ODS tries to pass in 20 parameters.   The first 10 are the new values and the second 10 are the old values.

For example, if you have a method:

UpdateMyFooObject(int ID, string Value);

ODS will look for a method called

UpdateMyFooObject(int ID, string Value, int original_ID, string original_Value);

To fix this, set OldValuesParameterFormatString to "{0}"

PJ

0
 

Author Comment

by:allanmark
ID: 24296925
Tks!

Had a look at the tutorial.  I'm not usign the "Configure Data Source wizard" or the "OldValuesParameterFormatString"  --  I'm doing mine without using the Designer (ie in Source and Code-behind).  So, I'm not to sure how I get to those parameters.

SOURCE:
 

    <asp:ObjectDataSource ID="spousalODS" runat="Server" SelectMethod="GetCouple" TypeName="BusinessLogic.Business" 

    OnSelected="spousalODS_Selected" OnSelecting="spousalODS_Selecting" UpdateMethod="SpousalODS_Update" >

            <SelectParameters >

                <asp:QueryStringParameter Name="CoupleId" DbType="int32" Direction="Input"  />

            </SelectParameters>    

         </asp:ObjectDataSource>  
 
 
 

CODE BEHIND:
 

    protected void SpousalODS_Update()   <========  All fields here?

    {

        bool updateSUccessful;
 

       updateSuccessful = Business.BusinessLogic.UpdateCouple()  <=== All fields here?

    }

Open in new window

0
 
LVL 11

Expert Comment

by:srikanthreddyn143
ID: 24297587
Can you show complete error message
0
 
LVL 8

Expert Comment

by:ppittle
ID: 24297647
ObjectDataSource UpdateMethod needs to be a method of BusinessLogic.Business, just as the SelectMethod, "GetCouple" is a method of BusinessLogic.Susiness.

Then, depending on the type returned from the ObjectDataSource's Select Method, the Update Method should take a single parameter of the same type, or have a parameter for every field in your FormView.  

Also, set the OldValuesParameterFormatString to "{0}" on your ObjectDataSource.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:allanmark
ID: 24297963
Hi!

I've done the changes (see attached snippet)  ---  not sure how to code the updateparameter in the Source ( the result of the Select is a DataTable)  -- can't find any parameter type equivalent for a DataTable!!!



srikanthreddyn143:
   "ObjectDataSource 'spousalODS' could not find a non-generic method 'SpousalODS_Update' that has parameters: C_Surname, C_Mar_Status, C_Wed_Anniv, C_Email, C_Active, ....."
SOURCE:
 

        <asp:ObjectDataSource ID="spousalODS" runat="Server" SelectMethod="GetCouple" TypeName="BusinessLogic.Business" 

    OnSelected="spousalODS_Selected" OnSelecting="spousalODS_Selecting" UpdateMethod="SpousalODS_Update" OldValuesParameterFormatString="{0}"  >

            <SelectParameters >

                <asp:QueryStringParameter Name="CoupleId" DbType="int32" Direction="Input"  />

            </SelectParameters>    

            <UpdateParameters>

                WHAT GOES HERE ??                 

            </UpdateParameters>

         </asp:ObjectDataSource>  
 
 

public static void SpousalODS_Update(DataTable dtCouple)

        {
 

            // Whatever we need to do here.

            .................
 

        }
 

public static DataTable GetCouple(int coupleId)

        {

            DataTable dtOurCouple = new DataTable();

            dtOurCouple = DataAccess.ReturnCouple(coupleId);            

            return dtOurCouple;

        }

Open in new window

0
 
LVL 8

Assisted Solution

by:ppittle
ppittle earned 250 total points
ID: 24298438
Allan,

I HIGHLY recommend you take a look at Scott Mitchell's tutorials http://www.asp.net/learn/data-access/ on using ObjectDataSources.  If you do 1,2 and 16, 17, you should have everything you need to accomplish what you're trying to do.

Additionally, if you use the DataSource Wizard, it'll automatically generate the UpdateParameters collection for you.  Once you've generated the UpdateParameters you'll need to make your update method, SpousalODS_Update have all the same parameters.  ie:

public static void SpousalODS_Update (string C_Surname, string C_Mar_Status, string C_Wed_Anniv, string C_Email, string C_Active, ...)


0
 

Author Comment

by:allanmark
ID: 24301913
Went through the tuts - makes a bit more sense now.

I'm just not looking forward to enetring 50+ parameters (which coudl grow to 75!!!
0
 
LVL 8

Expert Comment

by:ppittle
ID: 24304342
If you're application is simple enough and you don't need a Business Layer, you can use the ObjectDataSource to bind directly to a Strongly Typed DataAdapter (like those created in Tutorial 1).  If you are using Stored Procedures, or your Select query doesn't contain any Joins, Visual Studio should be able to automaticallys generate Insert, Update, and Delete statements for you.  So, if you set everything up right with Strongly Typed Data Sets, you could get a no code solution.

Of course, you could also try using straight SqlDataSources.
0
 

Author Closing Comment

by:allanmark
ID: 31580071
Many thanks!! Apologoes for delay in closing.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now