none
FormView will not Update Nullable Field of DataType Int RRS feed

  • Question

  • I have a LinqDataSource that selects * from a table.  The table has a field that is a nullable int.  The Nullable property of this field in the .dbml file it True.  The AllowNulls in the database is set to true.

     

    I create a DetailsView, set it's DataSource to the LinqDataSource and turn on Paging, Insert, Update and Delete.  I try to update the nullable int field to a value and it works.  I then try to update it to NULL and it works.

     

    I delete the DetailsView and create a FormView.  I set it's DataSource to the LinqDataSource and turn on Paging, Insert, Update and Delete.  I then have to delete the controls in the item, update and insert templates for the related objects.  I don't know why they are created here and not in a DetailsView.  I try to update the nullable int field to a value and it works.  I then try to update it to NULL and I get an error. 

     

    Failed to set one or more properties on type MyLinqProject.MyTable.  Ensure that the input values are valid and can be converted to the corresponding property types.

     

    What gives!?  Why is this different between the two controls?  What to do?

     

     

    Wednesday, May 28, 2008 8:37 PM

Answers

All replies

  • Can you post the exception stack trace here and also details of what your template for this field looks like?

     

    Thanks,

     

    [)amien

    Wednesday, May 28, 2008 11:32 PM
    Moderator
  • Stack Trace:

     

    [LinqDataSourceValidationException: Failed to set one or more properties on type TeddLinq.Item_Category.  Ensure that the input values are valid and can be converted to the corresponding property types.]
       System.Web.UI.WebControls.LinqDataSourceView.BuildDataObject(Type dataObjectType, IDictionary inputParameters) +528
       System.Web.UI.WebControls.LinqDataSourceView.BuildUpdateDataObjects(Object table, IDictionary keys, IDictionary values, IDictionary oldValues) +244
       System.Web.UI.WebControls.LinqDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +142
       System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +78
       System.Web.UI.WebControls.FormView.HandleUpdate(String commandArg, Boolean causesValidation) +1150
       System.Web.UI.WebControls.FormView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +440
       System.Web.UI.WebControls.FormView.OnBubbleEvent(Object source, EventArgs e) +95
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
       System.Web.UI.WebControls.FormViewRow.OnBubbleEvent(Object source, EventArgs e) +109
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
       System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +115
       System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +132
       System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +177
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
    

     

    The Page Source:

     

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Item_Default" %>

    <%@ Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI.WebControls" TagPrefix="asp" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head runat="server">

    <title>Untitled Page</title>

    </head>

    <body>

    <form id="form1" runat="server">

    <div>

    <asp:FormView ID="FormView1" runat="server" AllowPaging="True" DataKeyNames="Item_Category_Id" DataSourceID="LinqDataSource1">

    <EditItemTemplate>

    Item_Category_Id:

    <asp:Label ID="Item_Category_IdLabel1" runat="server" Text='<%# Eval("Item_Category_Id") %>' />

    <br />

    Name:

    <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />

    <br />

    Description:

    <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>' />

    <br />

    Parent_Category_Id:

    <asp:TextBox ID="Parent_Category_IdTextBox" runat="server" Text='<%# Bind("Parent_Category_Id") %>' />

    <br />

    IsItemEnabled:

    <asp:CheckBox ID="IsItemEnabledCheckBox" runat="server" Checked='<%# Bind("IsItemEnabled") %>' />

    <br />

    IsItemSpecificEnabled:

    <asp:CheckBox ID="IsItemSpecificEnabledCheckBox" runat="server" Checked='<%# Bind("IsItemSpecificEnabled") %>' />

    <br />

    <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />

    &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />

    </EditItemTemplate>

    <InsertItemTemplate>

    Name:

    <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />

    <br />

    Description:

    <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>' />

    <br />

    Parent_Category_Id:

    <asp:TextBox ID="Parent_Category_IdTextBox" runat="server" Text='<%# Bind("Parent_Category_Id") %>' />

    <br />

    IsItemEnabled:

    <asp:CheckBox ID="IsItemEnabledCheckBox" runat="server" Checked='<%# Bind("IsItemEnabled") %>' />

    <br />

    IsItemSpecificEnabled:

    <asp:CheckBox ID="IsItemSpecificEnabledCheckBox" runat="server" Checked='<%# Bind("IsItemSpecificEnabled") %>' />

    <br />

    <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />

    &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />

    </InsertItemTemplate>

    <ItemTemplate>

    Item_Category_Id:

    <asp:Label ID="Item_Category_IdLabel" runat="server" Text='<%# Eval("Item_Category_Id") %>' />

    <br />

    Name:

    <asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>' />

    <br />

    Description:

    <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Bind("Description") %>' />

    <br />

    Parent_Category_Id:

    <asp:Label ID="Parent_Category_IdLabel" runat="server" Text='<%# Bind("Parent_Category_Id") %>' />

    <br />

    IsItemEnabled:

    <asp:CheckBox ID="IsItemEnabledCheckBox" runat="server" Checked='<%# Bind("IsItemEnabled") %>' Enabled="false" />

    <br />

    IsItemSpecificEnabled:

    <asp:CheckBox ID="IsItemSpecificEnabledCheckBox" runat="server" Checked='<%# Bind("IsItemSpecificEnabled") %>' Enabled="false" />

    <br />

    <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />

    &nbsp;<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" />

    &nbsp;<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New" />

    </ItemTemplate>

    </asp:FormView>

    <asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="TeddLinq.ItemDataContext" EnableDelete="True" EnableInsert="True" EnableUpdate="True" OrderBy="Name" TableName="Item_Category">

    </asp:LinqDataSource>

    </div>

    </form>

    </body>

    </html>

     

    The Table:

    Item_Category  << table name

    Item_Category_Id  int  no nulls

    Name  varchar(50)  no nulls

    Description  varchar(100)  nulls

    Parent_Category_Id  int  nulls

    Item_Enabled  bit  no nulls

    Item_Specific_Enabled  bit  no nulls

    Thursday, May 29, 2008 1:54 PM
  • When you say you updating the field to null are you removing the value to leave the input box blank?

    Does inserting a new item without a parentCategoryID value entered work or does this also fail like update?

    Thanks,

    [)amien
    Friday, June 6, 2008 8:54 AM
    Moderator
  • Adam has the necessary instructions here on how to modify the ASP template to ensure that blank is converted into null

     

    http://forums.microsoft.com/Forums/ShowPost.aspx?PostID=3449186&SiteID=1

     

    Regards,

     

    [)amien

    Friday, June 6, 2008 10:18 PM
    Moderator