Link to home
Start Free TrialLog in
Avatar of allanmark
allanmark

asked on

ObjectDataSource UpdateMethod fails

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
ASKER CERTIFIED SOLUTION
Avatar of ppittle
ppittle
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of allanmark
allanmark

ASKER

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

Avatar of srikanthreddyn143
Can you show complete error message
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.
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

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!!!
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.
Many thanks!! Apologoes for delay in closing.