Solved

Form view won't update

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why don't I see this table in EDMX file? 2 23
Registering DLL 5 43
How do ASP.NET and MVC work together? 4 29
Syntax error 9 45
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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 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

16 Experts available now in Live!

Get 1:1 Help Now