Solved

Form view won't update

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 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