Solved

Form view won't update

Posted on 2014-10-02
4
172 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

740 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