Solved

ObjectDataSource UpdateMethod fails

Posted on 2009-05-04
9
649 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

912 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

22 Experts available now in Live!

Get 1:1 Help Now