January 9, 2012

SharePoint 2010: The data source control failed to execute the insert command.

Problem:

When modifying a Form of a list with SharePoint Designer 2010, at some point you might get error:

Error while executing web part: System.ArgumentException: Value does not fall within the expected range

The data source control failed to execute the insert command.

This may only occur with a specific type of List Form (New, Edit,Display).

Solution:

While there can be many causes for this generic error message, in my case the first parameter or ddwrt:DataBind function inside the SharePoint:FormFields element was 'i' and I was working with an Edit Form. Changing it to 'u' as it was with every other FormField fixed the issue.

<SharePoint:FormField runat="server" id="ff1{$Pos}" ControlMode="Edit" FieldName="Esittaja" __designer:bind="{ddwrt:DataBind('u',concat('ff1',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Esittaja')}" />

Explanation:

DataBind operation type parameters (the first parameter) are listed below:

'i' stands for INSERT,
'u' stands for UPDATE,
'd' stands for DELETE.

More about ddwrt:DataBind syntax can be found from Bryan's article.

2 comments:

  1. Jussi,
    I'm getting this on a form with anonymous access and i can't figure out why.
    Form is here:
    http://365.webbrewers.com/Pages/default.aspx

    ReplyDelete
  2. I got the same error:

    If you have diplayed any custom columns or lookup columns or calculated columns in edit/new forms you must have manually entered its sharepoint control tag.
    In that tag change the to ControlMode="Display" from ControlMode="Edit"/ControlMode="New"

    Hope it helps

    ReplyDelete