Ask a questionAsk a question
 

AnswerError message "non-generic method" using ObjectDataSource and GridView

  • Tuesday, May 17, 2005 10:18 PMcrbeckman Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Here is my process: (all with visual web developer 2005 Express, April version.)

    1.  create new dataset in the app_code folder, called interaction.xsd.  (right-click on the app_code directory and select new...)

    a.  Step through the TableAdapter Configuration Wizard.
    b.  Select the data connection (ManagementConnection String (Web.config)
    c.  Create new stored procedures
    d.  sql statement "SELECT Interaction.* FROM Interaction
    e.  new stored procedure names:  InteractionSelect_sp, InteractionInsert_sp, InteractionUpdate_sp, InteractionDelete_sp
    f.  Fill method: FillInteraction, Get method:  GetInteraction
    g.  Checked Create methods to send updates directly...
    h.  I now have Interaction.xsd.

    2.  Create new content page (code in separate file (Visual Basic) and uses master page), called Interaction.aspx.

    3.  In Design view, drag an ObjectDataSource onto the page.

    a.  (Configure Data Source) Selected InteractionTableAdapters.InteractionSelect_spTableAdapter.
    b.  Select method:  GetInteraction(), return...
    c.  Update method:  Update(Nullable<INT32> iFirmID, ...  (Each field in the Interaction table is listed, as well as "Original_iInteractionID, Int32".)
    d.  Insert method:  Insert(Nullable(int32> iFirmID,...(again, each field in the Interaction table is listed.)
    e.  Delete method:  Delete(Int32 Original_iTransactionID), returns Int32

    4.  Drag a Gridview object onto the page.

    a.  Choose Data Source - ObjectDataSource1 selected.
    b.  Select "Enable Editing" and "Enable Deleting" also for the Gridview.

    5.  ctl-F5, select the page from the page navigation.  Data is pulled from the database and is correct.  Click on the Edit link, click on the Update link.

    6.  Get the non-generic method error.
     
    Server Error in '/IntraVis' Application.

    ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'Update' that has parameters: iFirmID, iContactID, vcType, vcSubType, vcContent, vcCmtRmk, vcAddInfo, rTimeSpent, dtDTGEntered, vcUserNameEntered, original_iInteractionID.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidOperationException: ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'Update' that has parameters: iFirmID, iContactID, vcType, vcSubType, vcContent, vcCmtRmk, vcAddInfo, rTimeSpent, dtDTGEntered, vcUserNameEntered, original_iInteractionID.


    What am I doing wrong?  What step am I missing?

    chuck

Answers

  • Saturday, November 12, 2005 12:07 AMBradleyMSFTUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    By default, the DataSet designer generates and Update stored procedures that allow editing of the primary key, so the signature of InteractionUpdate_sp will look like this:

    InteractionUpdate_sp (iInteractionID, iFirmID, iContactID, vcType, vcSubType, vcContent, vcCmtRmk, vcAddInfo, rTimeSpent, dtDTGEntered, vcUserNameEntered, original_iInteractionID)

    The GridView, on the other hand, assumes that the primary key is read-only, so it doesn't pass a new value for the primary key field, and therefore ObjectDataSource looks for a sproc that doesn't have this parameter.  To make your page work, you have two options:

    1)  If you want updateable primary keys, edit the GridView columns and set ReadOnly=false on the BoundField associated to the InteractionID field.

    2)  If you don't want updateable primary keys, edit the definition of the InteractionUpdate_sp sproc to remove this parameter and regenerate the TableAdapter from the new sproc definition.

    Hope this helps,
    Bradley
    Web Platform and Tools Team
  • Friday, September 01, 2006 3:17 AMJack Burton Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    I had this problem also, in a nutshell here is what I did to resolve these problems:

    -Removed the "original_" from the  "original_{0}" OldValuesParameterFormatString property

    This solved the original error, but then I started getting this error:
    Value cannot be null.
    Parameter name: Original_Item

    I solved this new error by edited the XML produced by the dataset. I just went into the Update function code and change the "(WHERE ColumnID = :Original_ColumnID) " to (WHERE ColumnID = :ColumnID) and then deleted the "Original_ColumnID" from the object datasource parameters.

    Basically, unless for some strange reason you need to update the column ID, you can just change the Update function produced by the dataset to use the current column id in the WHERE clause.

    Hope this helps...

All Replies

  • Saturday, November 12, 2005 12:07 AMBradleyMSFTUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    By default, the DataSet designer generates and Update stored procedures that allow editing of the primary key, so the signature of InteractionUpdate_sp will look like this:

    InteractionUpdate_sp (iInteractionID, iFirmID, iContactID, vcType, vcSubType, vcContent, vcCmtRmk, vcAddInfo, rTimeSpent, dtDTGEntered, vcUserNameEntered, original_iInteractionID)

    The GridView, on the other hand, assumes that the primary key is read-only, so it doesn't pass a new value for the primary key field, and therefore ObjectDataSource looks for a sproc that doesn't have this parameter.  To make your page work, you have two options:

    1)  If you want updateable primary keys, edit the GridView columns and set ReadOnly=false on the BoundField associated to the InteractionID field.

    2)  If you don't want updateable primary keys, edit the definition of the InteractionUpdate_sp sproc to remove this parameter and regenerate the TableAdapter from the new sproc definition.

    Hope this helps,
    Bradley
    Web Platform and Tools Team
  • Friday, April 21, 2006 6:31 PMtwisterjosh Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Once you set the ReadOnly attribute of the ID field to False, you then get a useful:

    Value cannot be null.
    Parameter name: XXX

    Error...

  • Sunday, May 07, 2006 4:02 PMTremint Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    How do you do this. I dont know where to set the ReadOnly attribute

  • Sunday, June 04, 2006 6:34 PMSDS-Consulting Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Actually, just set the oldvaluesparameter.... on the ODS to {0} instead of original_{0}

    That will fix it without all the other stuff discussed above.

     

    Basically on the id field it's trying to set "Original_ID" instead of "ID" (this assumes your column is ID

  • Wednesday, June 21, 2006 7:32 AMscokim Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    that works.

    Brilliant !

    Thank you.
  • Monday, August 14, 2006 5:01 PMRosebuds Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I simply replaced the parameter name from what it was "ContractorID" to "original_ContractorID" since that what it was looking for, though I'm not sure how to change that request.

    All I did was change the names and it worked.

    The code generated looks for the name you entered in the proc, don't change the proc, just change the name in the code since the CLR has it's mind made up to look for what it wants, give it what it wants.

    Hope this helps somebody, I have 6 hours into digging for a solution, found this link in a blog got it to work and added this post
  • Monday, August 14, 2006 5:42 PMRosebuds Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
     Busy Dragon wrote:
    I simply replaced the parameter name from what it was "ContractorID" to "original_ContractorID" since that what it was looking for, though I'm not sure how to change that request.

    All I did was change the names and it worked.

    The code generated looks for the name you entered in the proc, don't change the proc, just change the name in the code since the CLR has it's mind made up to look for what it wants, give it what it wants.

    Hope this helps somebody, I have 6 hours into digging for a solution, found this link in a blog got it to work and added this post


    UPDATE: Change this
     OldValuesParameterFormatString="original_{0}"
    to
     OldValuesParameterFormatString="{0}"
  • Wednesday, August 16, 2006 3:08 AMShirajul Alam Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    sorry to inform that

    UPDATE: Change this
     OldValuesParameterFormatString="original_{0}"
    to
     OldValuesParameterFormatString="{0}"
     did not work in my case.

     

  • Wednesday, August 16, 2006 5:14 PMRosebuds Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Did you try to rename anything else or just that one thing?  I had to change the parameter name and viola it worked. But I tried nearly 100 other things too in addition to scouring the Web for an answer.  Maybe one of the other things I tried will help you.  Maybe...
  • Friday, August 18, 2006 5:05 AMTareq1176 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    It did not work with me but what I did to make it work  i have changed the paramaters of my function as in the exception .

    so look at the exception detail

     

    Exception Details: System.InvalidOperationException: ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'UpdateSupplierAddress' that has parameters: supplierID, Address, City, Country, original_SupplierID, CompanyName, Phone

    Here is my old  function with the error

    Public Function UpdateSupplierAddress(ByVal supplierID As Integer, ByVal address As String, ByVal city As String, ByVal country As String) As Boolean

    and here after the  update

    Public Function UpdateSupplierAddress(ByVal supplierID As Integer, ByVal address As String, ByVal city As String, ByVal country As String, ByVal original_supplierID As Integer, ByVal CompanyName As String, ByVal Phone As String) As Boolean

    This sample code was taken from the following article

    http://www.asp.net/learn/dataaccess/tutorial02vb.aspx?tabid=63

    so if you download the sample and add a simple page with objectdatasource and a detailsview  you will get that error so you must change the functions to include the original_code and other missing parameters .

     

    Regards

  • Wednesday, August 30, 2006 7:17 AMMichael Freidgeim Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     Busy Dragon wrote: UPDATE: Change this  OldValuesParameterFormatString="original_{0}"
    to  OldValuesParameterFormatString="{0}"

    Unfortunutely it 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 as described here.

  • Thursday, August 31, 2006 7:23 AMsace22 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    This is my solution that work for me. Go to xsd File and find Parameters Element for the update command then comment out the primary key(let's say "ID") and delete ID=[@ID] in command Text Element.
    Then it 's work.


    By the way, the solution to make ID column "ReadOnly" property = False is also work for me to.

    Hope it 's work for you too.

    PS : For SDS-Consulting Comment is not work for me neither
  • Friday, September 01, 2006 12:25 AMTyfud Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Had the same problem with a DAL, and a BLL on top of that. Way I got around it was to write my update function in the BLL to be something like this:

        Public Function UpdatePhoto(ByVal LocationGrouping As String, ByVal Description As String, ByVal ImageTakenDate As DateTime, ByVal original_ImageID As Int64) As Boolean
            Adapter.UpdateQuery(LocationGrouping, Description, ImageTakenDate, original_ImageID)
            Return True
        End Function

    Then, it captures the original_ID as it's passed to the function.

    I don't include the ID column in the Gridview, it's not even declared as a bound field. I do have it declared as a datakey however. Now, I only set up 3 parameters, being my 3 form parameters that I want to update comming from the Gridview.

    And it's done. No fuss, no mess, no choppy looking hacks. This is what the BLL and DAL were designed to do. Problem is, I was trying to do part of it's job for it, hence the ID field appearing twice. Take a step back, accept the gridview ID parameter, and you're good to go.
  • Friday, September 01, 2006 3:17 AMJack Burton Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    I had this problem also, in a nutshell here is what I did to resolve these problems:

    -Removed the "original_" from the  "original_{0}" OldValuesParameterFormatString property

    This solved the original error, but then I started getting this error:
    Value cannot be null.
    Parameter name: Original_Item

    I solved this new error by edited the XML produced by the dataset. I just went into the Update function code and change the "(WHERE ColumnID = :Original_ColumnID) " to (WHERE ColumnID = :ColumnID) and then deleted the "Original_ColumnID" from the object datasource parameters.

    Basically, unless for some strange reason you need to update the column ID, you can just change the Update function produced by the dataset to use the current column id in the WHERE clause.

    Hope this helps...
  • Friday, September 08, 2006 11:32 AMJ-Key Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Just to set the record straight on this (since no one has so far): I have just moved from 1.0 to 2.0, and discovered that this was one problem I shared with many others. Some of the suggestions to creative solutions here does not explain why it is happening, but offers instead a lot of work-around solutions. Some of these work for some, but no one is explaining what is going on.

    The issue is (apparently) that the gridview requires your sprocs params to match the names of the table columns AND that they include params for all the columns, whether you use them or not(!). This I found out from reading this article by Esposito: http://msdn.microsoft.com/msdnmag/issues/04/08/GridView/

    Hope that helps someone.

    PS: After only a week with vs 2005/Asp.net 2.0 I am beginning to think MS has gone way too far when it comes to creating a drag and drop tool for developers. I for one like to know what the drags and drops actually produce in terms of code and html, but I am still pondering over where vs 2005 is hiding it all(!) . For example, if the params in the html of gridview are not the params it is actually passing back, where are they? (obviously in a hidden xml file...) Is there for example any other way to open the xsd file of the dataset than going through the class viewer? And what if I don't want to propagate the records back to the db on every edit, can I just update the dataset and keep it in a state bag until I want to batch-update? Sad not to be able to tap into the new ado.net features... And why are all the MS demos using such simplified and inrealistic examples....? Argh!

  • Friday, September 08, 2006 6:30 PMJ-Key Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I believe the root of your problems is that there is a mismatch between the column names and the params names, which have to be the same(!) AND you need to include a param for every column regardless if the sproc actually needs them(!!). I guess it was a cheap way to generalize things. In the end, you will (of course?) remove the prefix on the key column proc in the ObjDataSource. And then it will magically work even when you regenerate your dataset.

    See  http://msdn.microsoft.com/msdnmag/issues/04/08/GridView/#S6

  • Saturday, September 09, 2006 1:22 AMcodequest Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    http://forums.asp.net/1393988/ShowThread.aspx#1393988

    another interpretation of this issue, with a fix (for some cases)

  • Saturday, September 16, 2006 1:58 AMcodequest Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    found a solution approach, some cases, posted here (please pardon the newbie-ese)

    http://forums.asp.net/thread/1393956.aspx

    has a lot to do with the fact that the update method stored in these situations includes a "select" (to return the ID value) on the back end of the "update".

    The objectdatasource (ODS) "wiring" tries to provide parameters for both the update (which uses Original_ID) and the select (which uses ID)...so puts both in (ODS) parameter list.   Then it can't match it to the update query.  

    >>> a part of this problem is that the error message is not very precise about describing this...and the update command won't show the select query unless you look at it right (described at above post)

    Trick is to change the update command text to use original_ID in the select, and delete the ID from the objectdatasource update parameters.  Then the ODS signature matches the update command signature.

  • Saturday, September 16, 2006 1:59 AMcodequest Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    seems to be seems to be some some dup dup dup duplication going on
  • Monday, October 02, 2006 12:45 AMcodequest Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    ...just a heads up...I tripped over a use case (which I then lost track of) which  -MAY- have suggested that the explanation/fix provided above (re: the "select" tacked onto the "update") -MAY- have only pertained to ID = identity...so in case you're not using ID = identity and the fix doesn't work, that -MIGHT- be why.  

    Also, I have not found one reason under the dome of the sky as to why that select query is tacked onto the update query.  The tableadapter seems to only be capable of returning an integer from the update.  Perhaps it came out of internals for  generating the equivalent stored procedure, and the developers left it in for the tableadapter method.  'Sa puzzle.

  • Tuesday, October 17, 2006 11:15 AMparag nikhal Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    hi

     this sloves my update prob. but creates same prob. with delete

     

     

  • Thursday, October 26, 2006 11:26 AMMark Delderfield Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks, that fixed my problem.
  • Monday, January 29, 2007 2:56 PMdanleis Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi There,

    I know it is a quite old problem, but there is no proper solution, so I am providing another one just for fun that includes all the advantages of those mentioned before. The basic problem for me was, that I had to go through the whole process every time I changed something. Obviously Visual Studio regenerates the designer code every time the schema has been changed.

    So I created a custom control to do the most of the work. To use it, optimistic concurrency option should be turned off for the table adapter. The sample code follows:

        public class UpdatableObjectDataSource : ObjectDataSource
        {
            private const string OriginalIdState = "OriginalIdFormat";
            private const string PrimaryKeyState = "PrimaryKey";
            private const string DefaultView = "DefaultView";
            private const string SimpleOriginalFormat = "{0}";

            private string primaryKey = string.Empty;
            private string originalFormat = string.Empty;

            public UpdatableObjectDataSource()
            {
                Initialize();
            }

            public UpdatableObjectDataSource(string typeName, string selectMethod)
                : base(typeName, selectMethod)
            {
                Initialize();
            }

            private void Initialize()
            {
                DataSourceView dv = this.GetView(DefaultView);

                this.Deleting += new ObjectDataSourceMethodEventHandler(UpdatableObjectDataSource_Deleting);
                this.Updating += new ObjectDataSourceMethodEventHandler(UpdatableObjectDataSource_Updating);
                this.Selected += new ObjectDataSourceStatusEventHandler(UpdatableObjectDataSource_Selected);
            }

            void UpdatableObjectDataSource_Updating(object sender, ObjectDataSourceMethodEventArgs e)
            {
                string origId = string.Format(originalFormat, primaryKey);

                if (e.InputParameters.Contains(primaryKey) && e.InputParameters.Contains(origId))
                    e.InputParameters[origId] = e.InputParameters[primaryKey];
            }

            protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);

                if (ViewState[PrimaryKeyState] != null)
                    this.primaryKey = ViewState[PrimaryKeyState].ToString();
                if (ViewState[OriginalIdState] != null)
                    this.originalFormat = ViewState[OriginalIdState].ToString();
            }

            void UpdatableObjectDataSource_Selected(object sender, ObjectDataSourceStatusEventArgs e)
            {
                if (e.ReturnValue is DataTable)
                {
                    if (((DataTable)e.ReturnValue).PrimaryKey.Length == 1)
                    {
                        primaryKey = ((DataTable)e.ReturnValue).PrimaryKey[0].ColumnName;

                        if(ViewState[PrimaryKeyState] == null)
                            this.ViewState.Add(PrimaryKeyState, primaryKey);
                    }
                }
            }

            void UpdatableObjectDataSource_Deleting(object sender, ObjectDataSourceMethodEventArgs e)
            {
                string origId = string.Format(originalFormat, primaryKey);

                if (e.InputParameters.Contains(primaryKey))
                {
                    if (e.InputParameters.Contains(origId))
                        e.InputParameters[origId] = e.InputParameters[primaryKey];

                    e.InputParameters.Remove(primaryKey);
                }
            }

            public new string OldValuesParameterFormatString
            {
                get { return base.OldValuesParameterFormatString; }
                set
                {
                    originalFormat = value;

                    if (ViewState[OriginalIdState] == null)
                        ViewState.Add(OriginalIdState, originalFormat);

                    base.OldValuesParameterFormatString = SimpleOriginalFormat;
                }
            }
        }
  • Friday, February 02, 2007 7:57 PMPaul Pleasant Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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}"

    This will solve the majority of these issues.

  • Saturday, February 03, 2007 11:58 AMdanleis Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    That's right. But if you change the scema the studio generates back the code, and your changes are lost.
  • Sunday, May 20, 2007 7:09 AMxAnonymousx Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Another reason why this error:

    Value cannot be null.

    Parameter name: Original_Item

    occurs is because the value is not being passed to the Update/Delete function (Duh!). But the reason why its not passed is probably due to missing DataKeyNames="Item" property on the DataBound control. For more information see http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.deleteparameters.aspx - How delete parameters are created and depend on DataKeyNames.

    For even more detail, see: http://msdn2.microsoft.com/en-us/library/ms228051.aspx

     

    ~xa

  • Sunday, October 28, 2007 6:26 PMejgarci Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    The change of OldValuesParameterFormatString  no function, the solution is:

     

    1) Go to DataSet Designer

    2) Click in the properties Table Adapter

    3) Modify the SQL Update query and rewrite the parameter key field parameter to:

     

    Example Query

     

    The Query Wizard make below SQL Update Command

     

    UPDATE    Clientes
    SET              CodCli = @CodCli, Nombre = @Nombre, Apellido = @Apellido
    WHERE     (CodCli = @Original_CodCli)

     

    Modify the Key parameter by the original Key

     

    UPDATE    Clientes
    SET              CodCli = @Original_CodCli, Nombre = @Nombre, Apellido = @Apellido
    WHERE     (CodCli = @Original_CodCli)

     

    The Wizard make two parameters but the first no have bindins in the Viewer page object render, and the objectdatasource fail when execute the query.

     

    Ejgarci

    system engineer

     

  • Tuesday, November 13, 2007 10:43 AMChris Arbon Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    I would like to point out that any field name with a space is also a problem. Lets say you have a table with three field names

     

    KeyField ,Field One,Field Two ( as opposed to FieldOne or FieldTwo).

     

    In this circumstance even though you have set the KeyField to ReadOnly = false in Edit Columns. The paramter list in the error message will be as follows : KeyField,Field_One,Field_Two,Original_KeyField,Field One,Field Two.

     

    In the parameter list those field names with a space are listed twice - Once with an underscrore and once without an underscore. The only solution I have is to change the field names to remove any spaces.

  • Tuesday, November 13, 2007 11:40 AMMichael Freidgeim Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    To change the field names to remove any spaces(and other unusual characters) is a very good idea. It will avoid problems if you will work with different designers, code generaters, ORM tools.
  • Monday, January 28, 2008 7:33 AMsaloniprasad Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    can u please be more specific on how to rectify the problem of

    Value cannot be null.
    Parameter name: Original_Item
     

    i donot know where to find XML produced by the dataset. is it the .designer.cs file where i have to make the changes in the update function?

     

  • Thursday, January 31, 2008 11:07 AMArchiev Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I've got a question. Do I need all columns from my datatbase in gridview for updating? Because I can't use update only when gridview doesn't include all columns from my database. My gridview is to large with all this columns . Even hiding this columns cause error when updating.

    Error is

    ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'Update' that has parameters: UserId, UserName, MobileAlias, IsAnonymous, LastActivityDate, original_ApplicationId, original_LoweredUserName, LoweredUserName.

    I tried to find some solution but nothing work


  • Thursday, January 31, 2008 11:35 AMMichael Freidgeim Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Add a new Update adapter method with the parameters that gridView expects. See my post

    Editable GridView with ObjectDatasource and Update method parameters.

  • Thursday, January 31, 2008 1:27 PMArchiev Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Ok . I tried your solution but it still doesn't work.

    In my GridView I want to have columns:

    UserName, IsAnonymous, LastActivityDate

    To my GridView I added all columns and set columns: AplicationId, MobileAlias, UserId , LoweredUserName to ReadOnly,Visibile=false. Other columns are only ReadOnly=false.

    Then 

    5. Return to strongly-typed dataset  XSD designer and add new Update adapter method with the parameters that gridView expects.


    So i returned to my dataset. I choose Add Query then Create new stored procedure  --> Update and write this.

    UPDATE aspnet_Users
    SET UserName=@UserName, IsAnonymous=@IsAnonymous, LastActivityDate=@LastACtivityDate,  ApplicationId=@original_ApplicationId,  LoweredUserName=@original_LoweredUserName

    Next i saved this query and set update method in ObjectDataSource to this new query.
    Update still doesn't work , but there is a different error :


    Cannot insert duplicate key row in object 'dbo.aspnet_Users' with unique index 'aspnet_Users_Index'.
    The statement has been terminated.


    So, i don't know what's up Stick out tongue    Because I think that i'm updating database so i don't create row with duplicate key, only update some columns in this row. Maybe I don't understand your solution well . Pleas help :]
  • Thursday, January 31, 2008 1:45 PMejgarci Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi guy, you make this:

     

    1) Make the datatable adapater using the wizard (drag an drop the database table to designer xsd)

    2) Generate all CRUD SQL to the table

    3) In the update instruccion modify this deleting the Original_KEY word to KEY only in the WHERE condition

    4) Bind the ObjectDataSources and the Datagrid

    5) In the ObjectDataSource modify the oldvalueformat Original_{0} to {0}

     

     

    Activate the operations add, new, delete, edit in the GridView.

     

     

    Bye.

     

  • Thursday, January 31, 2008 2:12 PMArchiev Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I write this :

    UPDATE aspnet_Users
    SET UserName=@UserName, IsAnonymous=@IsAnonymous, LastActivityDate=@LastACtivityDate,

    ApplicationId=@original_ApplicationId , LoweredUserName=@original_LoweredUserName
    WHERE (ApplicationId=ApplicationId) AND (LoweredUserName=LoweredUserName )


    but i still have error:

    Cannot insert duplicate key row in object 'dbo.aspnet_Users' with unique index 'aspnet_Users_Index'.
    The statement has been terminated.


  • Thursday, January 31, 2008 3:15 PMejgarci Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Verify if the primary key ('aspnet_Users_Index') in the table is the same in the XSD DataTable, When you write custom sql instructions not warraty to generate SQL compatible intrucctions to the schema.

     

    I think the clausule WHERE need the prymary key to locate the row.

     

     

    .

  • Friday, February 01, 2008 11:02 AMArchiev Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed Answer
    Yes, you're right. I noticed that the xsd designer after creating tableadapter put down incorrect primary key. I have changed it but i had to change also my UPDATE :



    UPDATE    aspnet_Users
    SET              UserName = @UserName, IsAnonymous = @IsAnonymous, LastActivityDate = @LastACtivityDate, UserId = @original_UserId
    WHERE     (UserId = @original_UserId)

    Difference: Original_UserId is not only in WHERE clausule

    Also I didn't change the OldValueParameterFormatString from original_{0} to {0}, because in my case it is only way to get what i want.

    Thank you very much Big Smile  Your advice was very useful Wink
  • Monday, November 02, 2009 8:44 PMdpb289 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I tried the following which works to my surprise!

    I am using LINQ-to-SQL but I'm certain the same is true for DataSet.

    The BLL argment-names in the update-method must match exactly the fieldnames found in the data table definition in the database. I confirmed this by looking at the generated xxxDataClasses.dbml.  In my scenario, the fieldnames I was using for the parameters did not match the data table definition (for example data table definition = "ProductId" but aspx = "productID".) When I used "productdID", it did not work. When I used "ProductId", it worked.