Solved

Form view won't update

Posted on 2014-10-02
4
161 Views
Last Modified: 2014-10-02
I have a asp.net aspx page with a form view that will not update.  I get this error message: "Cannot insert the value NULL into column 'FirstName', table 'SEI.dbo.tblIndividual'; column does not allow nulls. UPDATE fails. The statement has been terminated".  Obviously the parameters aren't being passed.  What's wrong?   Below is the code for the form view and datasource.  The form view defaults to Edit view.  Thanks for looking.

Steve

<asp:FormView ID="fvEditFiler" runat="server" DataKeyNames="IndivID" DataSourceID="dsFilerForEdit" DefaultMode="Edit">
            <EditItemTemplate>
                IndivID:
                <asp:Label ID="IndivIDLabel1" runat="server" Text='<%# Eval("IndivID") %>' />
                <br />
                FirstName:
                <asp:TextBox ID="FirstNameTextBox" runat="server" ReadOnly="True" Text='<%# Bind("FirstName") %>' />
                <br />
                LastName:
                <asp:TextBox ID="LastNameTextBox" runat="server" ReadOnly="True" Text='<%# Bind("LastName") %>' />
                <br />
                Address1:
                <asp:TextBox ID="Address1TextBox" runat="server" Text='<%# Bind("Address1") %>' />
                <br />
                Address2:
                <asp:TextBox ID="Address2TextBox" runat="server" Text='<%# Bind("Address2") %>' />
                <br />
                City:
                <asp:TextBox ID="CityTextBox" runat="server" Text='<%# Bind("City") %>' />
                <br />
                State:
                <asp:TextBox ID="StateTextBox" runat="server" ReadOnly="True" Text='<%# Bind("State") %>' />
                <br />
                Zip:
                <asp:TextBox ID="ZipTextBox" runat="server" Text='<%# Bind("Zip") %>' />
                <br />
                Email:
                <asp:TextBox ID="EmailTextBox" runat="server" Text='<%# Bind("Email") %>' />
                <br />
                Phone:
                <asp:TextBox ID="PhoneTextBox" runat="server" Text='<%# Bind("Phone") %>' />
                <br />
                Fax:
                <asp:TextBox ID="FaxTextBox" runat="server" Text='<%# Bind("Fax") %>' />
                <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>
                FirstName:
                <asp:TextBox ID="FirstNameTextBox" runat="server" Text='<%# Bind("FirstName") %>' />
                <br />
                LastName:
                <asp:TextBox ID="LastNameTextBox" runat="server" Text='<%# Bind("LastName") %>' />
                <br />
                Address1:
                <asp:TextBox ID="Address1TextBox" runat="server" Text='<%# Bind("Address1") %>' />
                <br />
                Address2:
                <asp:TextBox ID="Address2TextBox" runat="server" Text='<%# Bind("Address2") %>' />
                <br />
                City:
                <asp:TextBox ID="CityTextBox" runat="server" Text='<%# Bind("City") %>' />
                <br />
                State:
                <asp:TextBox ID="StateTextBox" runat="server" Text='<%# Bind("State") %>' />
                <br />
                Zip:
                <asp:TextBox ID="ZipTextBox" runat="server" Text='<%# Bind("Zip") %>' />
                <br />
                Email:
                <asp:TextBox ID="EmailTextBox" runat="server" Text='<%# Bind("Email") %>' />
                <br />
                Phone:
                <asp:TextBox ID="PhoneTextBox" runat="server" Text='<%# Bind("Phone") %>' />
                <br />
                Fax:
                <asp:TextBox ID="FaxTextBox" runat="server" Text='<%# Bind("Fax") %>' />
                <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>
                IndivID:
                <asp:Label ID="IndivIDLabel" runat="server" Enabled="False" Text='<%# Eval("IndivID") %>' />
                <br />
                FirstName:
                <asp:Label ID="FirstNameLabel" runat="server" Enabled="False" Text='<%# Bind("FirstName") %>' />
                <br />
                LastName:
                <asp:Label ID="LastNameLabel" runat="server" Enabled="False" Text='<%# Bind("LastName") %>' />
                <br />
                Address1:
                <asp:Label ID="Address1Label" runat="server" Text='<%# Bind("Address1") %>' />
                <br />
                Address2:
                <asp:Label ID="Address2Label" runat="server" Text='<%# Bind("Address2") %>' />
                <br />
                City:
                <asp:Label ID="CityLabel" runat="server" Text='<%# Bind("City") %>' />
                <br />
                State:
                <asp:Label ID="StateLabel" runat="server" Text='<%# Bind("State") %>' />
                <br />
                Zip:
                <asp:Label ID="ZipLabel" runat="server" Text='<%# Bind("Zip") %>' />
                <br />
                Email:
                <asp:Label ID="EmailLabel" runat="server" Text='<%# Bind("Email") %>' />
                <br />
                Phone:
                <asp:Label ID="PhoneLabel" runat="server" Text='<%# Bind("Phone") %>' />
                <br />
                Fax:
                <asp:Label ID="FaxLabel" runat="server" Text='<%# Bind("Fax") %>' />
                <br />
            </ItemTemplate>
        </asp:FormView>
<asp:SqlDataSource ID="dsFilerForEdit" runat="server" ConnectionString="<%$ ConnectionStrings:SEIConnectionString %>" SelectCommand="spGetFilerForEdit" SelectCommandType="StoredProcedure" UpdateCommand="UPDATE tblIndividual SET FirstName = @fName, LastName = @lName, Address1 = @addr1, Address2 = @addr2, City = @city, Zip = @zip, Email = @email, Phone = @phone, Fax = @fax WHERE IndivID = @indivID">
        <SelectParameters>
            <asp:SessionParameter Name="indivID" SessionField="indivID" Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <asp:SessionParameter Name="indivID" SessionField="indivID" Type="Int32" />
            <asp:Parameter Name="fName" />
            <asp:Parameter Name="lName" />
            <asp:Parameter Name="addr1" />
            <asp:Parameter Name="addr2" />
            <asp:Parameter Name="city" />
            <asp:Parameter Name="zip" />
            <asp:Parameter Name="email" />
            <asp:Parameter Name="phone" />
            <asp:Parameter Name="fax" />
        </UpdateParameters>
    </asp:SqlDataSource>
0
Comment
Question by:McLeanIS
  • 2
4 Comments
 
LVL 32

Expert Comment

by:Big Monty
ID: 40357464
i think you need to add the ControlID attribute to your UpdateParamters, otherwise it doesn't know what fields to use

<asp:Parameter Name="fName" ControlID="FirstNameTextBox" />

you'll need to map each parameter
0
 

Author Comment

by:McLeanIS
ID: 40357520
Big Monty,

Thanks for the response.  I tried what you posted but got an error on the format of the parameter.  I constructed the parameter as an asp:ControlParameter and got this error: "Could not find control 'FirstNameTextBox' in ControlParameter 'fName'".  What is the correct way to reference a field in a form view?
0
 
LVL 32

Accepted Solution

by:
Big Monty earned 500 total points
ID: 40357543
per this link, it looks like you need to specify the name of the formview as well:

<asp:Parameter Name="fName" ControlID="formViewID$FirstNameTextBox" />

if that doesn't work, maybe one of the .NET gurus can chime in, as my expertise is mostly classic asp, where this was originally posted
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now