Solved

Form view won't update

Posted on 2014-10-02
4
173 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 33

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 33

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

726 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