objectdatasource.update() fires System.InvalidOperationException

Discussion in 'ASP .Net Web Controls' started by Markus, Dec 21, 2005.

  1. Markus

    Markus Guest

    hello,
    we have a strange error message here:

    I've written a small detail sample page, where I can update one reocrd with
    an objectdatasource control and the detailsview control.
    the objectdatasource.confictdetection is set to 'CompareAllValues'. The
    Updatemethod is UpdateXY and I've set two updateparameters classX and
    original_callsX.

    when I use the update link provided by the detailsview control, everything
    works as expected.

    The problem comes now:
    I added a button on the page and labeled it 'Update'. In the clicked event I
    added the code objectdatasource1.Update().
    Here the following exception is fired immediatelly:
    You have specified that your update method compares all values on
    ObjectDataSource 'odsCommodity', but the dictionary passed in for oldValues
    is empty. Pass in a valid dictionary for update or change your mode to
    OverwriteChanges.
    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: You have specified that
    your update method compares all values on ObjectDataSource 'odsCommodity',
    but the dictionary passed in for oldValues is empty. Pass in a valid
    dictionary for update or change your mode to OverwriteChanges.

    You have specified that your update method compares all values on
    ObjectDataSource 'odsCommodity', but the dictionary passed in for oldValues
    is empty. Pass in a valid dictionary for update or change your mode to
    OverwriteChanges.
    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: You have specified that
    your update method compares all values on ObjectDataSource 'odsCommodity',
    but the dictionary passed in for oldValues is empty. Pass in a valid
    dictionary for update or change your mode to OverwriteChanges.

    Stack Trace:


    [InvalidOperationException: You have specified that your update method
    compares all values on ObjectDataSource 'odsCommodity', but the dictionary
    passed in for oldValues is empty. Pass in a valid dictionary for update or
    change your mode to OverwriteChanges.]
    System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(IDictionary
    keys, IDictionary values, IDictionary oldValues) +703
    System.Web.UI.WebControls.ObjectDataSourceView.Update(IDictionary keys,
    IDictionary values, IDictionary oldValues) +37
    System.Web.UI.WebControls.ObjectDataSource.Update() +42
    CommodityDetail.btnUpdate_Click(Object sender, EventArgs e) in
    c:\Application\vs2005\Sample2_ObjectDataSource_IEnum\UserInterface\CommodityDetail.aspx.cs:19
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +96
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
    +116

    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    sourceControl, String eventArgument) +32
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72
    System.Web.UI.Page.ProcessRequestMain(Boolean
    includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3838


    Any help?
    Thanks in advance
    Markus
    Markus, Dec 21, 2005
    #1
    1. Advertising

  2. Hi Markus,

    Welcome to ASPNET newsgroup.
    Regarding on the ObjectDatasource.Update method throw exception problem,
    based on my understanding, it is because when you manually call the
    ObjectDataSource.Update method, it hasn't be supplied the required
    inputParameters. When we use the DetailsView or GridView's "update" button,
    those parameters will be retrieved from the detailsview or GridView's
    current edit item....

    So for your scenario, we'd suggest you consider the following means to do
    update(for the current edit row) in our own submit button"

    1. Instead of calling ObjectDataSource.Update method, we call
    DetailsView.UpdateItem method, this method will update the current Item(in
    edit mode).. And it'll help retreive the required parameters from the
    DetailsView, just as when we click the "update" button generated by
    DetailsView..... e.g:

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
    if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
    {
    DetailsView1.UpdateItem(true);
    }

    }


    2. Also, we can use the ObjectDataSource.Update method, however, we need
    also intercept the event through the ObjectDatasource's "Updating" event,
    at there we can manually supply all the parameters required or updating.
    e.g:


    protected void btnUpdate_Click(object sender, EventArgs e)
    {
    if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
    {
    ObjectDataSource1.Update();
    }

    }


    protected void ObjectDataSource1_Updating(object sender,
    ObjectDataSourceMethodEventArgs e)
    {
    Response.Write("<br>Count: " + e.InputParameters.Count);
    foreach (System.Collections.DictionaryEntry param in
    e.InputParameters)
    {
    Response.Write("<br>" + param.Key + " " + param.Value);
    }

    }


    #I just print out all the required parameters ... You need to assign the
    correct value in each entry (since they're all empty when we manually call
    ObjectDataSource.Update....)


    Hope helps. Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)



    --------------------
    | Thread-Topic: objectdatasource.update() fires
    System.InvalidOperationException
    | thread-index: AcYGRsOhr5M0QfvRSXSvHlubW+2H5g==
    | X-WBNR-Posting-Host: 146.148.72.21
    | From: =?Utf-8?B?TWFya3Vz?= <>
    | Subject: objectdatasource.update() fires System.InvalidOperationException
    | Date: Wed, 21 Dec 2005 07:54:02 -0800
    | Lines: 72
    | Message-ID: <>
    | MIME-Version: 1.0
    | Content-Type: text/plain;
    | charset="Utf-8"
    | Content-Transfer-Encoding: 7bit
    | X-Newsreader: Microsoft CDO for Windows 2000
    | Content-Class: urn:content-classes:message
    | Importance: normal
    | Priority: normal
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
    | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
    | Xref: TK2MSFTNGXA02.phx.gbl
    microsoft.public.dotnet.framework.aspnet.webcontrols:31973
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    |
    | hello,
    | we have a strange error message here:
    |
    | I've written a small detail sample page, where I can update one reocrd
    with
    | an objectdatasource control and the detailsview control.
    | the objectdatasource.confictdetection is set to 'CompareAllValues'. The
    | Updatemethod is UpdateXY and I've set two updateparameters classX and
    | original_callsX.
    |
    | when I use the update link provided by the detailsview control,
    everything
    | works as expected.
    |
    | The problem comes now:
    | I added a button on the page and labeled it 'Update'. In the clicked
    event I
    | added the code objectdatasource1.Update().
    | Here the following exception is fired immediatelly:
    | You have specified that your update method compares all values on
    | ObjectDataSource 'odsCommodity', but the dictionary passed in for
    oldValues
    | is empty. Pass in a valid dictionary for update or change your mode to
    | OverwriteChanges.
    | 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: You have specified
    that
    | your update method compares all values on ObjectDataSource
    'odsCommodity',
    | but the dictionary passed in for oldValues is empty. Pass in a valid
    | dictionary for update or change your mode to OverwriteChanges.
    |
    | You have specified that your update method compares all values on
    | ObjectDataSource 'odsCommodity', but the dictionary passed in for
    oldValues
    | is empty. Pass in a valid dictionary for update or change your mode to
    | OverwriteChanges.
    | 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: You have specified
    that
    | your update method compares all values on ObjectDataSource
    'odsCommodity',
    | but the dictionary passed in for oldValues is empty. Pass in a valid
    | dictionary for update or change your mode to OverwriteChanges.
    |
    | Stack Trace:
    |
    |
    | [InvalidOperationException: You have specified that your update method
    | compares all values on ObjectDataSource 'odsCommodity', but the
    dictionary
    | passed in for oldValues is empty. Pass in a valid dictionary for update
    or
    | change your mode to OverwriteChanges.]
    |
    System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(IDictionary
    | keys, IDictionary values, IDictionary oldValues) +703
    | System.Web.UI.WebControls.ObjectDataSourceView.Update(IDictionary
    keys,
    | IDictionary values, IDictionary oldValues) +37
    | System.Web.UI.WebControls.ObjectDataSource.Update() +42
    | CommodityDetail.btnUpdate_Click(Object sender, EventArgs e) in
    c:\Application\vs2005\Sample2_ObjectDataSource_IEnum\UserInterface\Commodity
    Detail.aspx.cs:19
    | System.Web.UI.WebControls.Button.OnClick(EventArgs e) +96
    | System.Web.UI.WebControls.Button.RaisePostBackEvent(String
    eventArgument)
    | +116
    |
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
    stBackEvent(String eventArgument) +31
    | System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    | sourceControl, String eventArgument) +32
    | System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72
    | System.Web.UI.Page.ProcessRequestMain(Boolean
    | includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3838
    |
    |
    | Any help?
    | Thanks in advance
    | Markus
    |
    |
    Steven Cheng[MSFT], Dec 22, 2005
    #2
    1. Advertising

  3. Hi Markus,

    Any progress on this issue or does my last reply helps a little?
    If there're anything else we can help, please feel free to post here.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    --------------------
    | X-Tomcat-ID: 104388298
    | References: <>
    | MIME-Version: 1.0
    | Content-Type: text/plain
    | Content-Transfer-Encoding: 7bit
    | From: (Steven Cheng[MSFT])
    | Organization: Microsoft
    | Date: Thu, 22 Dec 2005 06:23:09 GMT
    | Subject: RE: objectdatasource.update() fires
    System.InvalidOperationException
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    | Message-ID: <>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    | Lines: 178
    | Path: TK2MSFTNGXA02.phx.gbl
    | Xref: TK2MSFTNGXA02.phx.gbl
    microsoft.public.dotnet.framework.aspnet.webcontrols:32003
    | NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
    |
    | Hi Markus,
    |
    | Welcome to ASPNET newsgroup.
    | Regarding on the ObjectDatasource.Update method throw exception problem,
    | based on my understanding, it is because when you manually call the
    | ObjectDataSource.Update method, it hasn't be supplied the required
    | inputParameters. When we use the DetailsView or GridView's "update"
    button,
    | those parameters will be retrieved from the detailsview or GridView's
    | current edit item....
    |
    | So for your scenario, we'd suggest you consider the following means to do
    | update(for the current edit row) in our own submit button"
    |
    | 1. Instead of calling ObjectDataSource.Update method, we call
    | DetailsView.UpdateItem method, this method will update the current
    Item(in
    | edit mode).. And it'll help retreive the required parameters from the
    | DetailsView, just as when we click the "update" button generated by
    | DetailsView..... e.g:
    |
    | protected void btnUpdate_Click(object sender, EventArgs e)
    | {
    | if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
    | {
    | DetailsView1.UpdateItem(true);
    | }
    |
    | }
    |
    |
    | 2. Also, we can use the ObjectDataSource.Update method, however, we need
    | also intercept the event through the ObjectDatasource's "Updating" event,
    | at there we can manually supply all the parameters required or updating.
    | e.g:
    |
    |
    | protected void btnUpdate_Click(object sender, EventArgs e)
    | {
    | if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
    | {
    | ObjectDataSource1.Update();
    | }
    |
    | }
    |
    |
    | protected void ObjectDataSource1_Updating(object sender,
    | ObjectDataSourceMethodEventArgs e)
    | {
    | Response.Write("<br>Count: " + e.InputParameters.Count);
    | foreach (System.Collections.DictionaryEntry param in
    | e.InputParameters)
    | {
    | Response.Write("<br>" + param.Key + " " + param.Value);
    | }
    |
    | }
    |
    |
    | #I just print out all the required parameters ... You need to assign the
    | correct value in each entry (since they're all empty when we manually
    call
    | ObjectDataSource.Update....)
    |
    |
    | Hope helps. Thanks,
    |
    | Steven Cheng
    | Microsoft Online Support
    |
    | Get Secure! www.microsoft.com/security
    | (This posting is provided "AS IS", with no warranties, and confers no
    | rights.)
    |
    |
    |
    | --------------------
    | | Thread-Topic: objectdatasource.update() fires
    | System.InvalidOperationException
    | | thread-index: AcYGRsOhr5M0QfvRSXSvHlubW+2H5g==
    | | X-WBNR-Posting-Host: 146.148.72.21
    | | From: =?Utf-8?B?TWFya3Vz?= <>
    | | Subject: objectdatasource.update() fires
    System.InvalidOperationException
    | | Date: Wed, 21 Dec 2005 07:54:02 -0800
    | | Lines: 72
    | | Message-ID: <>
    | | MIME-Version: 1.0
    | | Content-Type: text/plain;
    | | charset="Utf-8"
    | | Content-Transfer-Encoding: 7bit
    | | X-Newsreader: Microsoft CDO for Windows 2000
    | | Content-Class: urn:content-classes:message
    | | Importance: normal
    | | Priority: normal
    | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
    | | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    | | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
    | | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
    | | Xref: TK2MSFTNGXA02.phx.gbl
    | microsoft.public.dotnet.framework.aspnet.webcontrols:31973
    | | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    | |
    | | hello,
    | | we have a strange error message here:
    | |
    | | I've written a small detail sample page, where I can update one reocrd
    | with
    | | an objectdatasource control and the detailsview control.
    | | the objectdatasource.confictdetection is set to 'CompareAllValues'. The
    | | Updatemethod is UpdateXY and I've set two updateparameters classX and
    | | original_callsX.
    | |
    | | when I use the update link provided by the detailsview control,
    | everything
    | | works as expected.
    | |
    | | The problem comes now:
    | | I added a button on the page and labeled it 'Update'. In the clicked
    | event I
    | | added the code objectdatasource1.Update().
    | | Here the following exception is fired immediatelly:
    | | You have specified that your update method compares all values on
    | | ObjectDataSource 'odsCommodity', but the dictionary passed in for
    | oldValues
    | | is empty. Pass in a valid dictionary for update or change your mode to
    | | OverwriteChanges.
    | | 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: You have specified
    | that
    | | your update method compares all values on ObjectDataSource
    | 'odsCommodity',
    | | but the dictionary passed in for oldValues is empty. Pass in a valid
    | | dictionary for update or change your mode to OverwriteChanges.
    | |
    | | You have specified that your update method compares all values on
    | | ObjectDataSource 'odsCommodity', but the dictionary passed in for
    | oldValues
    | | is empty. Pass in a valid dictionary for update or change your mode to
    | | OverwriteChanges.
    | | 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: You have specified
    | that
    | | your update method compares all values on ObjectDataSource
    | 'odsCommodity',
    | | but the dictionary passed in for oldValues is empty. Pass in a valid
    | | dictionary for update or change your mode to OverwriteChanges.
    | |
    | | Stack Trace:
    | |
    | |
    | | [InvalidOperationException: You have specified that your update method
    | | compares all values on ObjectDataSource 'odsCommodity', but the
    | dictionary
    | | passed in for oldValues is empty. Pass in a valid dictionary for
    update
    | or
    | | change your mode to OverwriteChanges.]
    | |
    | System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(IDictionary
    | | keys, IDictionary values, IDictionary oldValues) +703
    | | System.Web.UI.WebControls.ObjectDataSourceView.Update(IDictionary
    | keys,
    | | IDictionary values, IDictionary oldValues) +37
    | | System.Web.UI.WebControls.ObjectDataSource.Update() +42
    | | CommodityDetail.btnUpdate_Click(Object sender, EventArgs e) in
    |
    c:\Application\vs2005\Sample2_ObjectDataSource_IEnum\UserInterface\Commodity
    | Detail.aspx.cs:19
    | | System.Web.UI.WebControls.Button.OnClick(EventArgs e) +96
    | | System.Web.UI.WebControls.Button.RaisePostBackEvent(String
    | eventArgument)
    | | +116
    | |
    |
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
    | stBackEvent(String eventArgument) +31
    | | System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    | | sourceControl, String eventArgument) +32
    | | System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    +72
    | | System.Web.UI.Page.ProcessRequestMain(Boolean
    | | includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    +3838
    | |
    | |
    | | Any help?
    | | Thanks in advance
    | | Markus
    | |
    | |
    |
    |
    Steven Cheng[MSFT], Dec 28, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Kennedy
    Replies:
    0
    Views:
    1,532
    Jeff Kennedy
    Oct 20, 2003
  2. Hari Koduru
    Replies:
    3
    Views:
    1,358
    Natty Gur
    Jan 15, 2004
  3. Tony
    Replies:
    6
    Views:
    7,341
  4. Alejandro Penate-Diaz
    Replies:
    3
    Views:
    5,246
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=
    Dec 20, 2004
  5. Replies:
    3
    Views:
    993
Loading...

Share This Page