Solved

Getting error on ItemInserting event on Formview

Posted on 2014-04-22
7
252 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
  • 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 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