Solved

Getting error on ItemInserting event on Formview

Posted on 2014-04-22
7
255 Views
Last Modified: 2014-04-24
Hi,
I have a formview on my web page bound to a sql data source.  When I try to Insert a new record I get an error message that I cannot insert a null value in the adj_description column.  I'm not sure what I'm doing wrong; everything looks okay.

I've attached my sqldatasource code and my formview code

 <asp:FormView ID="fvInsertNewAdjusment" runat="server" 
                DataSourceID="AdjustmenttSqlDataSource" DefaultMode="Insert">
                <EditItemTemplate>
                    AdjID:
                    <asp:Label ID="AdjIDLabel1" runat="server" Text='<%# Eval("AdjID") %>' />
                    <br />
                    Lockbox:
                    <asp:TextBox ID="LockboxTextBox" runat="server" Text='<%# Bind("Lockbox") %>' />
                    <br />
                    Credit_Date:
                    <asp:TextBox ID="Credit_DateTextBox" runat="server" 
                        Text='<%# Bind("Credit_Date") %>' />
                    <br />
                    Adj_Description:
                    <asp:TextBox ID="Adj_DescriptionTextBox" runat="server" 
                        Text='<%# Bind("Adj_Description") %>' />
                    <br />
                    Adj_Amt:
                    <asp:TextBox ID="Adj_AmtTextBox" runat="server" Text='<%# Bind("Adj_Amt") %>' />
                    <br />
                    Created_By:
                    <asp:TextBox ID="Created_ByTextBox" runat="server" 
                        Text='<%# Bind("Created_By") %>' />
                    <br />
                    Create_Date:
                    <asp:TextBox ID="Create_DateTextBox" runat="server" 
                        Text='<%# Bind("Create_Date") %>' />
                    <br />
                    Last_Modified_By:
                    <asp:TextBox ID="Last_Modified_ByTextBox" runat="server" 
                        Text='<%# Bind("Last_Modified_By") %>' />
                    <br />
                    Last_Modified_Date:
                    <asp:TextBox ID="Last_Modified_DateTextBox" runat="server" 
                        Text='<%# Bind("Last_Modified_Date") %>' />
                    <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>
                    <table style="width:35%;">
                        <tr>
                            <td class="style6">
                                Lockbox:
                            </td>
                            <td>
                                <asp:TextBox ID="LockboxTextBox" runat="server" Text='<%# Bind("Lockbox") %>' />
                            </td>
                        </tr>
                        <tr>
                            <td class="style6">
                                Credit Date:</td>
                            <td>
                                <asp:TextBox ID="Credit_DateTextBox" runat="server" 
                                    Text='<%# Bind("Credit_Date", "{0:d}") %>' ReadOnly="True" />
                            </td>
                        </tr>
                        <tr>
                            <td class="style6">
                                Adjustment Description:
                            </td>
                            <td>
                                <asp:TextBox ID="Adj_DescriptionTextBox" runat="server" 
                                    Text='<%# Bind("Adj_Description") %>' Width="380px" Height="29px" />
                            </td>
                        </tr>
                        <tr>
                            <td class="style6">
                                Adjustment Amt:
                            </td>
                            <td>
                                <asp:TextBox ID="Adj_AmtTextBox" runat="server" Text='<%# Bind("Adj_Amt", "{0:N}") %>' 
                                    style="margin-left: 1px" />
                            </td>
                        </tr>
                    </table>
                    &nbsp;<asp:TextBox ID="Created_ByTextBox" runat="server" 
                        Text='<%# Bind("Created_By") %>' Visible="False" />
                    <asp:TextBox ID="Create_DateTextBox" runat="server" 
                        Text='<%# Bind("Create_Date") %>' Visible="False" />
                    <asp:TextBox ID="Last_Modified_ByTextBox" runat="server" 
                        Text='<%# Bind("Last_Modified_By") %>' Visible="False" />
                    <asp:TextBox ID="Last_Modified_DateTextBox" runat="server" 
                        Text='<%# Bind("Last_Modified_Date") %>' Visible="False" />
                    <br />
                    &nbsp;<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>
                <InsertRowStyle BackColor="White" BorderColor="Black" BorderStyle="Solid" />
                <ItemTemplate>
                    AdjID:
                    <asp:Label ID="AdjIDLabel" runat="server" Text='<%# Eval("AdjID") %>' />
                    <br />
                    Lockbox:
                    <asp:Label ID="LockboxLabel" runat="server" Text='<%# Bind("Lockbox") %>' />
                    <br />
                    Credit_Date:
                    <asp:Label ID="Credit_DateLabel" runat="server" 
                        Text='<%# Bind("Credit_Date") %>' />
                    <br />
                    Adj_Description:
                    <asp:Label ID="Adj_DescriptionLabel" runat="server" 
                        Text='<%# Bind("Adj_Description") %>' />
                    <br />
                    Adj_Amt:
                    <asp:Label ID="Adj_AmtLabel" runat="server" Text='<%# Bind("Adj_Amt") %>' />
                    <br />
                    Created_By:
                    <asp:Label ID="Created_ByLabel" runat="server" 
                        Text='<%# Bind("Created_By") %>' />
                    <br />
                    Create_Date:
                    <asp:Label ID="Create_DateLabel" runat="server" 
                        Text='<%# Bind("Create_Date") %>' />
                    <br />
                    Last_Modified_By:
                    <asp:Label ID="Last_Modified_ByLabel" runat="server" 
                        Text='<%# Bind("Last_Modified_By") %>' />
                    <br />
                    Last_Modified_Date:
                    <asp:Label ID="Last_Modified_DateLabel" runat="server" 
                        Text='<%# Bind("Last_Modified_Date") %>' />
                    <br />
                    <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                        CommandName="New" Text="New" />
                </ItemTemplate>
            </asp:FormView>

Open in new window


 <asp:SqlDataSource ID="AdjustmenttSqlDataSource" runat="server" 
                ConnectionString="<%$ ConnectionStrings:FMSConnectionString %>" 
                InsertCommand="INSERT INTO FMS_Reconciling_Adj(Lockbox, Credit_Date, Adj_Description, Adj_Amt, Created_By, Create_Date, Last_Modified_Date, Last_Modified_By) VALUES (@lockbox, @creditdate, @adj_desc, @adj_amt, @createdby, @createdate, @lastmodifieddate, @lastmodifiedby)" 
                SelectCommand="SELECT FMS_Reconciling_Adj.* FROM FMS_Reconciling_Adj" 
                ProviderName="<%$ ConnectionStrings:FMSConnectionString.ProviderName %>">
                <InsertParameters>
                    <asp:ControlParameter ControlID="txtbxLockbox" Name="lockbox" 
                        PropertyName="Text" />
                    <asp:ControlParameter ControlID="txtbxCreditDate" Name="creditdate" 
                        PropertyName="Text" />
                    <asp:Parameter Name="adj_desc" />
                    <asp:Parameter Name="adj_amt" />
                    <asp:Parameter Name="createdby" />
                    <asp:Parameter Name="createdate" DefaultValue="Now" />
                    <asp:Parameter Name="lastmodifieddate" DefaultValue="Now" />
                    <asp:Parameter Name="lastmodifiedby" />
                </InsertParameters>
            </asp:SqlDataSource>

Open in new window

0
Comment
Question by:imstac73
[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
  • 4
  • 2
7 Comments
 
LVL 12

Expert Comment

by:duttcom
ID: 40016410
At first glance, it looks like your parameter

<asp:Parameter Name="adj_desc" /> is not right - you haven't given adj_desc a value anywhere.

You either need to make it a control parameter that refers to the Adj_DescriptionTextBox ID in the listview-

<asp:ControlParameter ControlID="Adj_DescriptionTextBox" Name="adj_desc" />

or you will need to use the name of the bound field-

<asp:Parameter Name="Adj_Description" />
0
 

Author Comment

by:imstac73
ID: 40017505
Okay, I thought having the control bound in the formview handled that but I will update my parameter line in the sqldatasource code. Thanks.
0
 

Author Comment

by:imstac73
ID: 40017514
I added this code to my sqlserver datasource insert command:
<asp:ControlParameter ControlID="Adj_DescriptionTextBox" Name="adj_desc" />

I get the following error:
Could not find control 'Adj_DescriptionTextBox' in ControlParameter 'adj_desc'.
0
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 40020019
You have same name for this control in both Edit and Insert templates. What happens if you change the textbox name in edit template?

Also, you need to specify
PropertyName="Text"

in control parameter.
0
 

Author Comment

by:imstac73
ID: 40020068
I added the PropertyName="Text" to the parameter attributes and changed the name of the textbox control in the edittimetemplate and I am still getting the error.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 40020083
Does it work if you change the controlid to "fvInsertNewAdjusment$Adj_DescriptionTextBox"?
0
 

Author Comment

by:imstac73
ID: 40020269
Thanks that worked!  Very strange; I've never had to put the actual form name in the parameters.  Appreciate your help.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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